合并2个相同结构的嵌套表

时间:2019-10-03 11:21:03

标签: sap abap

是否可以在ABAP中用一条指令合并2个带有嵌套表字段的结构?我尝试过MOVE-CORRESPONDING,但没有设法得到它。

下面我写了我需要做的事情的简化版本,我的实际结构有更多的表,还有一些单独的字段,但是现在我只想简化下面的代码

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

1 个答案:

答案 0 :(得分:0)

在堆栈上,它们不喜欢ABAP宏,但是宏非常适合您想要执行的结构化任务:

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.