I have following internal table:
VBELN POSNR ELEMENT VALUE
4711 10 E1 12
4711 10 E2 23
Is there any possibility in ABAP (Framework, Class, etc), so I can fast create a new internal table at runtime which would look like this:
VBELN POSNR E1 E2
4711 10 12 23
Would appreciate any kind of help.
Thanks and BR.
What you want are the ABAP Runtime Type Services (RTTS) or ABAP Runtime Type Creation (RTTC).
DATA(vbeln_descriptor) = CAST cl_abap_datadescr( cl_abap_typedescr=>describe_by_name( 'VBELN' ) ).
DATA(posnr_descriptor) = CAST cl_abap_datadescr( cl_abap_typedescr=>describe_by_name( 'POSNR' ) ).
DATA(components) = VALUE abap_component_tab( ( name = 'VBELN'
type = vbeln_descriptor )
( name = 'POSNR'
type = posnr_descriptor ) ).
DATA(value_descriptor) = cl_abap_typedescr=>describe_by_name( 'VALUE' ).
LOOP AT vbeln_rows INTO DATA(vbeln_row).
INSERT VALUE #(
name = vbeln_row-element
type = value_descriptor )
INTO TABLE components.
ENDLOOP.
DATA(row_descriptor) = cl_abap_structdescr=>get( components ).
DATA(table_descriptor) = cl_abap_tabledescr=>create( row_descriptor ).
DATA itab TYPE REF TO data.
CREATE DATA itab TYPE HANDLE table_descriptor.