2022 Nov 12 7:19 PM
Hello,
I have an internal table storing some of the customer's data and I want to append a column from another table which stores e-mail addresses. LIFNR is the common field between tables.
I have the function itself already working:
LOOP AT gt_email_addr INTO gwa_email_addr.
LOOP AT gt_main INTO gwa_main.
IF gwa_main-lifnr = gwa_email_addr-lifnr.
gwa_main-smtp_addr = gwa_email_addr-smtp_addr.
MODIFY gt_main FROM gwa_main.
ENDIF.
ENDLOOP.
ENDLOOP.
BUT I would prefer it to work as a FOR loop. At the moment I am trying something like this:
gt_main = VALUE #( BASE gt_main FOR wa IN gt_email_addr ( CORRESPONDING #( wa ) ) ).
But it doesn't work - the line above actually just appends a new record to gt_main. The documentation seems to be very "tip-of-the-iceberg" about it and provides just some theory and all other sources explain how I can use such a loop to add literal values provided within the code instead and I can't find anything about moving data from one table to another in this way.
2022 Nov 13 9:50 AM
You should use Constructor Expressions only to construct values once (construct = "initialize values from scratch"), not construct again just to mimic an update, it will be simply counter-performing.
If you can Construct only once, at a specific place, if you have all data sources available, then you can use VALUE/FOR and any constructor expression you need.
2022 Nov 13 2:30 PM
Hey,
Thanks for the answer. Do I understand correctly then than my current solution (LOOP within a LOOP) is the correct way to go if I want move data from a single column of an internal table to another internal table?
And that my attempts at optimization should in fact be used only if I want to create a new table?
Kind Regards,
2022 Nov 14 12:29 PM
rule-of-thumb:
2022 Nov 14 10:59 AM
"The documentation seems to be very "tip-of-the-iceberg" about it and provides just some theory" - really? The documentation provides you with two examples which suit your use case:
https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenfor_in_itab.htm
Lena
2022 Dec 19 8:47 AM
Hey,
Thank you for the answer and sorry for the late reply.
I've been trying with these, but I really couldn't see how the presented examples fit my use-case. It feels like they're solving a different problem, albeit I suppose this can be attributed to me still being a junior in SAP.
I will analyse it deeper.
Kind Regards,
Bartek