1

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 ) ).
Suncatcher
  • 10,355
  • 10
  • 52
  • 90
RaTiO
  • 979
  • 2
  • 17
  • 33
  • 2
    As far as I know, any other solution will be more complex than those 4 lines of code. – Sandra Rossi Oct 03 '19 at 12:07
  • Considering that I have more than just 2 nested tables in my real scenario, I guess I can create a method to dynamically do this, but I thought ABAP could help here. I will leave the question open for now. – RaTiO Oct 04 '19 at 17:22
  • `append lines of tab1 to tab2` . But you want a generic solution that works anywhere ? A nested move-corresponding is more than 4 lines of code and is non trivial when ALL abap types are considered. Not sure what merging structures is anyway.... – phil soady Oct 10 '19 at 00:45
  • Maybe concatenate would be better than merge. But yes, I wanted a MOVE-CORRESPONDING that appends lines from source to target structure when the corresponding field is a table of the exact same type. – RaTiO Oct 10 '19 at 13:44

1 Answers1

0

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.
Suncatcher
  • 10,355
  • 10
  • 52
  • 90