'Concatenate using 'FOR' loop in VALUE operator with 'BASE' addition?

Is it possible to mix in a FOR with CONCATENATE along with BASE statement?

Normally, itab1 = VALUE #( BASE itab1 ( value1 ) ) will append line1 into itab1 without overwriting. Shouldn't it be the same when using FOR along with BASE?

This is my thought process, but I get the No component exists with the name "FOR" error:

itab1 = 
VALUE #( 
   BASE itab1
   ( value1 && value2 )
   ( VALUE #( 
       FOR line in itab2
       ( line-fld1 && line-fld2 ) )
   ).


Solution 1:[1]

I have tried out what Sandra had suggested in the comments and it worked like a charm:

You may append the lines of an internal table only by using ( LINES OF itab ), so in your case it should be ( LINES OF VALUE #( ... ) ) – Sandra Rossi

itab1 = 
VALUE #( BASE itab1 ( value1 && value2 )
       ( LINES OF VALUE #( FOR line in itab2 ( line-fld1 && line-fld2 ) ) ).

Solution 2:[2]

Shouldn't it be the same when using FOR along with BASE

Yes, the semantics is the same. You use BASE for preserving the rows of the LHS when adding rows of RHS, and line specification is the same:

itab1 = VALUE #( BASE itab1 FOR line in itab2 ( matnr = line-matnr
                                                maktx = line-matnr && line-spras
                                                spras = line-spras ) ).

However, there is a nuance you should remember here: you cannot put the same itab to the inline-declared LHS, to the BASE source and to the FOR loop, it will give you infinite loop and TSV_TNEW_PAGE_ALLOC_FAILED dump.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 isekaid_maou
Solution 2