A code snippet which creates DDIC structure during runtime using RTTI. This structure can then be used to created table type and also be used in ALV grids.
data: lt_component type abap_component_tab,
ls_component type abap_componentdescr,
ls_layout type slis_layout_alv.
data: l_obj_data type ref to data,
l_obj_s_data type ref to data.
* Spalten aufbauen:
l_subpsp_id = wa_sel-id.
* translate l_subpsp_id using '/_' .
*Eckstart
concatenate 'PSTRT_' l_subpsp_id into ls_component-name.
read table lt_component with key name = ls_component-name transporting no fields.
* Prüfen, ob Name schon vorhanden ist oder nicht:
check sy-subrc ne 0.
ls_component-type ?= cl_abap_typedescr=>describe_by_name( 'PS_PSTRT' ).
insert ls_component into table lt_component.
append initial line to it_fieldcat assigning .
-fieldname = ls_component-name.
concatenate 'EA' wa_sel-text into -seltext_m separated by space.
-col_pos = 0.
*Eckende
concatenate 'PENDE_' l_subpsp_id into ls_component-name.
ls_component-type ?= cl_abap_typedescr=>describe_by_name( 'PS_PENDE' ).
insert ls_component into table lt_component.
append initial line to it_fieldcat assigning .
-fieldname = ls_component-name.
concatenate 'EE' wa_sel-text into -seltext_m separated by space.
-col_pos = 0.
ls_component-type ?= cl_abap_typedescr=>describe_by_name( 'ZPSP_NETTO' ).
ls_component-name = 'NETTO'.
insert ls_component into table lt_component.
append initial line to it_fieldcat assigning .
-fieldname = ls_component-name.
-seltext_m = 'Nettowert'.
-col_pos = 0.
*... etc pp, wenn alle Spalten definiert sind:
* Instanziieren der internen Tabelle:
l_obj_struc ?= cl_abap_structdescr=>create( lt_component ).
l_obj_table ?= cl_abap_tabledescr=>create( l_obj_struc ).
free: lt_component.
create data l_obj_data type handle l_obj_table.
assign l_obj_data->* to .
create data l_obj_s_data type handle l_obj_struc.
assign l_obj_s_data->* to .