I have two internal tables with a content: itab1, itab2 and one final table ftab. I need to move the contents from itab1 and itab2 to ftab with corresponding values.
For example, move the first record of itab1 to the corresponging first record of ftab and also the first record of itab2 to the corresponding first record of ftab keeping all the values from both tables. Basically it means to merge the contents of the first records of both tables and put it into the final table.
I can do it by using ftab = CORRESPONDING #( itab1 ), subsequent looping at ftab, reading itab2 and filling the remaining columns.
I want to know - is there any way to do it without using loop?
Actually there is no possibility to merge as described 2 tables into a third one without looping. Using
CORRESPONDINGit is possible just to add second table's content after the content of the first one.What is actually possible is to make the looping and filling the target table in one statemet using iteration expression
FORand component operatorCORRESPONDING. Below I wrote an example code for this.Data declarations:
Fill in some sample data:
Build a target table
lt_ftabwhich is a merge of the two above:If you use this statement instead:
the content of two tables will be just added together but not merged.