'Merge nested tables in deep structure between two itabs

I need some help to find the fastest and easiest way to merge some nested tables. For Example:

TYPES: BEGIN OF TEST,
        SFLIGHT1 TYPE SFLIGHT,
        MARA1    TYPE MARA,
        END OF TEST.

DATA: ITAB TYPE TABLE OF TEST,
      WA   TYPE TEST.
DATA: ITAB2 TYPE TABLE OF TEST,
      WA2   TYPE TEST.
DATA: LT_SFLIGHT1 TYPE SFLIGHT,
      LT_SFLIGHT2 TYPE SFLIGHT.
DATA: LT_MARA1 TYPE MARA,
      LT_MARA2 TYPE MARA.

WA-SFLIGHT1 = LT_SFLIGHT1.
WA-MARA1 = LT_MARA1.
APPEND WA TO ITAB.

WA2-SFLIGHT2 = LT_SFLIGHT2.
WA2-MARA2 = LT_MARA2.
APPEND WA2 TO ITAB2.

Now I want to append lines of from ITAB to ITAB2, WA-SFLIGHT1 to WA2-SFLIGHT2 and WA-MARA1 to WA2-MARA2 without creating a new line in ITAB2.

For Example: ITAB has 1 line with WA-SFLIGHT1 which has 3 lines and WA-MARA1 which has 6 lines. ITAB2 has 1 line with WA2-SFLIGHT2 which has 6 lines and WA2-MARA2 which has 6 lines. Now I want to append the 3 lines of WA-SFLIGHT1 and the 6 lines of WA-MARA1 from ITAB to WA2-SFLIGHT2 and WA2-MARA2 into ITAB2. At the end ITAB2 has 1 line with WA2-SFLIGHT2 with 9 lines (3 from ITAB) and WA2-MARA2 with 12 lines (6 from ITAB).

It should be something dynamic because in my case, I have a deep structure with 6 tables which lines I need to append to a new structure within an ITAB without creating a new line in ITAB itself only in the structure-table.

Thanks a lot.



Sources

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

Source: Stack Overflow

Solution Source