‎2021 Apr 03 10:19 AM
Hi Expert team:
we have 2 internal table:
ITAB1 has same structure like bapi2017_gm_item_create
ITAB2 has more fields and some fields like in bapi2017_gm_item_create
We would like to modify ITAB1 so we can pass information to BAPI call later.
How to modify ITAB1 with information from ITAB2 pls.
Both ITAB1 and ITAB2 has same field which is PO_Number and PO_Item.
We are not sure how to loop:
Should it be like this
Loop ITAB2
Read ITAB1 with key fields ITAB2-PO_Number and ITAB2-PO_Item
Move ITAB2-field1 to ITAB1-field1
Modify ITAB1
Endloop.
pls advise and many thanks.
‎2021 Apr 03 10:39 AM
Hi,
You can do it like you wrote.
Or you can try MOVE-CORRESPONDING.
MOVE-CORRESPONDING itab2 TO itab1. Kind regards,
Mateusz
‎2021 Apr 03 10:39 AM
Hi,
You can do it like you wrote.
Or you can try MOVE-CORRESPONDING.
MOVE-CORRESPONDING itab2 TO itab1. Kind regards,
Mateusz
‎2021 Apr 03 11:01 AM
A few more questions:
1.Which one is better
Loop ITAB1
Read ITAB2
Endloop
or
loop ITAB2
Read iTAB1
Endloop
2. When using MoDIFY do I need to MoDIFY with sy-tabix or not?
pls help again and many thanks.
‎2021 Apr 03 11:31 AM
If you use REFERENCE TO then you do not need the MODIFY statement. That's best.
As to which LOOP sequence is better - it depends on your internal tables' definitions (with or without key, what is the condition) and the number of records. Whether these are sorted or not.
Kind regards,
Mateusz
LOOP AT itab2 REFERENCE INTO ld_itab2.
READ TABLE itab1 REFERENCE INTO ld_itab1 WITH...
ld_itab2->field = ld_itab1->field.
ENDLOOP.
‎2021 Apr 03 1:20 PM
Here lt_itab1 and lt_itab2 have the same type, but it works also for two tables, which with a different type (bapi2017_gm_item_create_t is a table of bapi2017_gm_item_create).
DATA(lt_itab1) = VALUE bapi2017_gm_item_create_t( ( po_number = '1234567890' po_item = '12345') ).
DATA(lt_itab2) = CORRESPONDING bapi2017_gm_item_create_t( lt_itab1 ).