ABAP動態內表

tbmr發表於2024-10-23
TYPES:BEGIN OF l_person,
        pernr TYPE pernr_d,
      END OF l_person .
TYPES: t_person TYPE TABLE OF l_person .
DATA: lt_person TYPE TABLE OF l_person .

lt_person = VALUE #(
  ( pernr = '1263' )
  ( pernr = '1264' )
).

TYPES:BEGIN OF l_job,
        objid TYPE objid,
      END OF l_job .
TYPES: t_job TYPE TABLE OF l_job .
DATA: lt_job TYPE TABLE OF l_job .

lt_job = VALUE #(
  ( objid = '180001' )
  ( objid = '180002' )
).

TYPES: BEGIN OF l_type,
         type_name  TYPE char30,
         table_name TYPE char30,
       END OF l_type .
DATA: lt_type TYPE TABLE OF l_type,
      ls_type TYPE l_type.

lt_type = VALUE #(
  ( type_name = 't_person' table_name = 'lt_person' )
  ( type_name = 't_job'    table_name = 'lt_job' )
).


DATA: dy_tab  TYPE REF TO data.
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE, 
               <dyn_temp>  TYPE STANDARD TABLE.

TYPES: BEGIN OF l_tab,
         content TYPE REF TO data,
       END OF l_tab .
DATA: lt_tab TYPE TABLE OF l_tab,
      ls_tab TYPE l_tab.

LOOP AT lt_type INTO ls_type.
  CREATE DATA ls_tab-content TYPE (ls_type-type_name).
  ASSIGN (ls_type-table_name) TO <dyn_temp>.
  ASSIGN ls_tab-content->* TO <dyn_table> .
  MOVE-CORRESPONDING <dyn_temp> TO <dyn_table> .
  APPEND ls_tab TO lt_tab .
ENDLOOP.

相關文章