Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

New ABAP Syntax for modifying internal tables

VishwanathV
Participant
37,427

Hi,

Is there any way to modify an internal table using new abap syntax, possibly within FOR...IN iteration? I need to modify the value in a column of each row of an existing internal table and assign it to a new internal table. I was trying to use something like this:

TYPES: tt_1 TYPE TABLE OF YGT_COST WITH EMPTY KEY.

DATA: lr_gen TYPE REF TO data.

FIELD-SYMBOLS: <tab> TYPE STANDARD TABLE.

FIELD-SYMBOLS: <line1> TYPE ANY.

CREATE DATA lr_gen TYPE STANDARD TABLE OF YGT_COST WITH EMPTY KEY.

ASSIGN lr_gen->* TO <tab>.

CREATE DATA lr_gen TYPE YGT_COST.

ASSIGN lr_gen->* TO <line1>.*

<tab> = ct_table.

DATA(lt_table) = VALUE tt_1( FOR <line> IN <tab> ( new_update = 'X' ) ).

*// However, the above statement is creating an internal table lt_table with the line type of <line> but it's only populating new_update colum with 'X'. Remaining columns are rendering as initial into the new internal table lt_table.

What i am expecting is to only update column new_update with 'X' and remaining columns should have values from <line> structure. Please note, Column to column mapping from <line> to the corresponding fields of lt_table is not feasible because of large number of columns involved.

Best Rgds,

Vish

7 REPLIES 7
Read only

srikanthnalluri
Active Participant
0 Likes
19,358

Using LET expression you can assign a value or assign value using logic to the intend field.

types:
  begin of ty_tab1,
    val1 type char1,
    val2 type i,
  end of ty_tab1,
  tt_tab1 type standard table of ty_tab1 with empty key.

data(lt_tab1) = value tt_tab1(
                   ( val1 = 'A' val2 = 100 )
                   ( val1 = 'B' val2 = 200 ) ).

cl_demo_output=>write( lt_tab1 ).

* LET
data(lt_tab2) = value tt_tab1(
                  for wa in lt_tab1 index into idx
                  let x = wa-val2 + idx
                  in ( val1 = wa-val1 val2 = x ) ).

cl_demo_output=>write( lt_tab2 ).
cl_demo_output=>display( ).
Read only

VijayCR
Active Contributor
0 Likes
19,358

Did you find any solution to this ?

Read only

Former Member
0 Likes
19,358

This syntax is known and already worked on it. But I was actually looking for ABAP 7.50. For Example ...Below is the way to populate the internal table (replacement of Loop).

DATA(gt_citys) = VALUE ty_citys( FOR ls_ship IN gt_ships WHERE ( route = ‘R0001’ ) ( ls_ship–city ) ).

Read only

DoanManhQuynh
Active Contributor
0 Likes
19,358

Vijaya Simha Chintarlapalli Reddy

you may using function method after LET to modify which fields you need:

DATA(itab1) = VALUE #( FOR ls1 in tab2 LET ls_tmp = conv_class->conv( ls1 ) IN ( ls_tmp ) ).
Read only

Sandra_Rossi
Active Contributor
19,358

I'm confused:

The question title let think people that you want to just update one component of one internal table.

But the question inside is about to transfer to another internal table, with one component set to a fixed value and all the other components of the structure should be transferred unchanged.

So I will answer to both questions (because other answers confused me).

1) To answer what's in the title: "new ABAP"? If you mean via a "construction expression" only, NO, because it's only to "create" data, not to "update". To update, you have to use the "old" ABAP statements... but you may still use a construction expression inside them (parentheses are needed because <tab> has a generic line type):

MODIFY <tab> FROM VALUE ygt_cost( new_update = 'X' ) TRANSPORTING ('new_update') WHERE (`new_update <> 'X'`). 

More information: MODIFY itab_lines

2) To answer the actual question, to transfer all other components, use BASE:

DATA(lt_table) = VALUE tt_1( FOR <line> IN <tab> ( VALUE ygt_cost( BASE <line> new_update = 'X' ) ) ).

More information: VALUE #|dtype( BASE ... ) for structures

Read only

Sandra_Rossi
Active Contributor
0 Likes
19,358
Read only

Sandra_Rossi
Active Contributor
0 Likes
19,358

vishwanath vedula Please use the CODE button to format your code.