REPORT z_dynamic_03.
TYPE-POOLS: abap.
DATA: lr_structdescr TYPE REF TO cl_abap_structdescr,
lr_tabledescr TYPE REF TO cl_abap_tabledescr,
lr_datadescr TYPE REF TO cl_abap_datadescr,
lt_comp TYPE abap_component_tab,
ls_comp TYPE abap_componentdescr,
lr_wa TYPE REF TO data,
lr_tab TYPE REF TO data.
DATA : lv_idx TYPE n LENGTH 2.
FIELD-SYMBOLS:
FIELD-SYMBOLS:
FIELD-SYMBOLS:
PARAMETER p_cnt TYPE i.
START-OF-SELECTION.
DO p_cnt TIMES.
lv_idx = lv_idx + 1.
CONCATENATE 'column' lv_idx INTO ls_comp-name
SEPARATED BY '_'.
CALL METHOD cl_abap_elemdescr=>get_i
RECEIVING
p_result = ls_comp-type.
INSERT ls_comp INTO TABLE lt_comp.
ENDDO.
CALL METHOD cl_abap_structdescr=>create
EXPORTING
p_components = lt_comp
RECEIVING
p_result = lr_structdescr.
CREATE DATA lr_wa TYPE HANDLE lr_structdescr.
ASSIGN lr_wa->* TO
lr_datadescr = lr_structdescr.
CALL METHOD cl_abap_tabledescr=>create
EXPORTING
p_line_type = lr_datadescr
receiving
p_result = lr_tabledescr .
CREATE DATA lr_tab TYPE HANDLE lr_tabledescr.
ASSIGN lr_tab->* TO
DO p_cnt TIMES.
DO.
ASSIGN COMPONENT sy-index
OF STRUCTURE
IF sy-subrc NE 0. EXIT. ENDIF.
ENDDO.
APPEND
ENDDO.
LOOP AT
DO.
ASSIGN COMPONENT sy-index
OF STRUCTURE
TO
IF sy-subrc IS NOT INITIAL. EXIT. ENDIF.
WRITE
ENDDO.
WRITE / .
ENDLOOP.