Search code examples
abapinternal-tables

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

  • 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 ) ) ).