Code: Alles auswählen.
FORM return_components USING ur_typedescr TYPE REF TO cl_abap_typedescr
CHANGING ct_component TYPE abap_component_tab.
DATA:
lt_component_sub TYPE abap_component_tab,
lt_component_org TYPE abap_component_tab,
lt_component_new TYPE abap_component_tab,
lr_structdescr TYPE REF TO cl_abap_structdescr,
lr_tabledescr TYPE REF TO cl_abap_tabledescr,
lr_datadescr TYPE REF TO cl_abap_datadescr,
lr_refdescr TYPE REF TO cl_abap_refdescr,
lr_typedescr TYPE REF TO cl_abap_typedescr.
FIELD-SYMBOLS:
<ls_component_sub> TYPE abap_componentdescr,
<ls_component> TYPE abap_componentdescr.
REFRESH ct_component.
IF ur_typedescr IS NOT BOUND.
RETURN.
ENDIF.
lr_typedescr = ur_typedescr.
* Referenzen auflösen
WHILE lr_typedescr->kind EQ cl_abap_typedescr=>kind_ref.
lr_refdescr ?= lr_typedescr.
lr_typedescr = lr_refdescr->get_referenced_type( ).
ENDWHILE.
CASE lr_typedescr->kind.
WHEN cl_abap_typedescr=>kind_table.
lr_tabledescr ?= lr_typedescr.
lr_datadescr = lr_tabledescr->get_table_line_type( ).
lr_typedescr = lr_datadescr.
PERFORM return_components USING lr_typedescr CHANGING ct_component.
WHEN cl_abap_typedescr=>kind_struct.
lr_structdescr ?= lr_typedescr.
lt_component_org = lr_structdescr->get_components( ).
* Prüfen ob es Includes gibt die aufgelöst werden müssen
READ TABLE lt_component_org TRANSPORTING NO FIELDS WITH KEY as_include = abap_true.
* Wenn keine Includes gefunden wurden...
IF sy-subrc NE 0.
* ... die zuvor erstelle Struktur zurückgeben ...
ct_component = lt_component_org.
* ... sonst auflösen und neu erstellen
ELSE.
REFRESH lt_component_new.
LOOP AT lt_component_org ASSIGNING <ls_component>.
IF <ls_component>-as_include EQ abap_true.
lr_typedescr = <ls_component>-type.
PERFORM return_components USING lr_typedescr CHANGING lt_component_sub.
IF <ls_component>-suffix IS NOT INITIAL.
LOOP AT lt_component_sub ASSIGNING <ls_component_sub>.
CONCATENATE <ls_component_sub>-name <ls_component>-suffix INTO <ls_component_sub>-name.
ENDLOOP.
ENDIF.
INSERT LINES OF lt_component_sub INTO TABLE lt_component_new.
ELSE.
INSERT <ls_component> INTO TABLE lt_component_new.
ENDIF.
ENDLOOP.
ct_component = lt_component_new.
ENDIF.
WHEN cl_abap_typedescr=>kind_elem.
APPEND INITIAL LINE TO ct_component ASSIGNING <ls_component>.
* <ls_component>-name = 'TABLE_LINE'.
<ls_component>-type ?= lr_typedescr.
ENDCASE.
ENDFORM.
Code: Alles auswählen.
DATA: lr_typedescr TYPE REF TO cl_abap_typedescr,
lt_component TYPE abap_component_tab.
lr_typedescr = cl_abap_typedescr=>describe_by_data( ... ).
PERFORM return_components USING lr_typedescr CHANGING lt_component.
Folgende Benutzer bedankten sich beim Autor a-dead-trousers für den Beitrag (Insgesamt 2):
ibo • Icke0801