2023 Mar 14 2:59 AM
Hi,
I have first internal table with 2 columns cocd, descrp, ( blank internal table)
Second internal table have 3 columns- title, charvalue, charname, in that , I have entry called fr30 under first column, france under second column, cocd under third column.
So i want to move this fr30 & France to the cocd and descrp respectively without hard coding( since I have thousands of entries like this)
I tried like this,
if gs-charname = 'cocd'.
Move gs_tab2-title to gs_tab1-cocd.
Move gs_tab2-charvalue to gs_tab1-descp.
I have some 50 fields like this so, is there any other way.
Thanks in advance
2023 Mar 14 6:51 AM
Hello sun_light
have a look at Move-Corresponding
We all know about this keyword and we have been since we learned it. For the benefit of me, I would like to define it once again.
MOVE-CORRESPONDING is used to move values from one structure to another.
Now that you can not wait to know how this works for internal tables. I have to keep you waiting a little longer and introduce you to a new ABAP 7.4 keyword, a constructor operator called CORRESPONDINGLets make this example even more complex, i have two different set of columns for the two internal tables and copy the column named COL2 of first internal table to COL3 of second internal table and the code is
TYPES : BEGIN OF lty_demo1,
col1 TYPE c,
col2 TYPE c,
END OF lty_demo1,
BEGIN OF lty_demo2,
col1 TYPE c,
col2 TYPE c,
col3 TYPE c,
END OF lty_demo2.
DATA: itab1 TYPE STANDARD TABLE OF lty_demo1,
itab2 TYPE STANDARD TABLE OF lty_demo2.
itab1 = VALUE #( ( col1 = 'A' col2 = 'B' )
( col1 = 'P' col2 = 'Q' )
( col1 = 'N' col2 = 'P' )
).
itab2 = CORRESPONDING #( itab1 MAPPING COL3 = COL2 EXCEPT COL2 ).
cl_demo_output=>write_data( itab1 ).
cl_demo_output=>write_data( itab2 ).
cl_demo_output=>display( ).
regards
Christian Fritsch
2023 Mar 14 7:05 AM
You are searching to use dynamic fieldname like that ?
data(field) = 'GS_TAB1-' && gs-charname.
assign (field) to field-symbol(<field_content>).
if <field_content> is assigned.
move gs_tab2-title to <field_content>.
endif.
2023 Mar 14 9:10 AM
Or
assign COMPONENT gs-charname OF STRUCTURE gs_tab1 TO FIELD-SYMBOL(<fs>).
Also check field names are in uppercase?