Reputation: 1049
Is it possible to merge 2 structures with nested table fields with a single instruction in ABAP? I tried with MOVE-CORRESPONDING but I didn't manage to get it.
Below I wrote a simplified version of what I need to do, my real structure has more tables and also some individual field, but for now I'm only asking to simplify the code below
TYPES: BEGIN OF ty_nested_tables,
table1 TYPE STANDARD TABLE OF ty_table1,
table2 TYPE STANDARD TABLE OF ty_table2,
END OF ty_nested_tables.
DATA: nested1 TYPE ty_nested_tables,
nested2 TYPE ty_nested_tables,
nested3 TYPE ty_nested_tables.
I know this could be grouped in a single VALUE for the full nested3 variable but the part I want to simplify is the need for specifying table1 and table2 when they are same name and type than the target
nested3-table1 = VALUE #( ( LINES OF nested1-table1 )
( LINES OF nested2-table1 ) ).
nested3-table2 = VALUE #( ( LINES OF nested1-table2 )
( LINES OF nested2-table2 ) ).
Upvotes: 1
Views: 1281
Reputation: 10621
Here on Stack they don't like ABAP macros, but macros are perfect for such structuring tasks like you wanna do:
DEFINE copy.
nested3-table&2 = VALUE #( BASE nested3-table&2 ( LINES OF nested&1-table&2 ) ).
END-OF-DEFINITION.
copy: 1 1, 1 2, 2 1, 2 2.
Upvotes: 0