2007 Jan 08 8:20 PM
HI, all. I need information and samples to create dynamical objects for Run Time Type Creation (RTTC). I am grateful for the help that they could offer to me. Thanks.
Message was edited by:
Martínez Vásquez Rubén Dario
Message was edited by:
Martínez Vásquez Rubén Dario
HI, all. I need information and samples to create dynamical objects for Run Time Type Creation (RTTC). I am grateful for the help that they could offer to me. Thanks.
Message was edited by:
Martínez Vásquez Rubén Dario
Message was edited by:
Martínez Vásquez Rubén Dario
2007 Jan 08 8:45 PM
2007 Jan 16 7:14 PM
HI, all. I need samples to create dynamical objects for Run Time Type Creation (RTTC). I am grateful for the help that they could offer to me. Thanks.
2022 Mar 12 7:33 AM
Hi,
Here is the sample program for creating structure and internal table dynamically.
DATA: lo_structtype TYPE REF TO cl_abap_structdescr,
lo_tabletype TYPE REF TO cl_abap_tabledescr,
lo_dataref TYPE REF TO data.
DATA: lt_comp TYPE cl_abap_structdescr=>component_table,
ls_comp LIKE LINE OF lt_comp.
FIELD-SYMBOLS: <lt_table> TYPE STANDARD TABLE,
<ls_table> TYPE any,
<ls_val> TYPE any.
ls_comp-name = 'MATNR'.
ls_comp-type ?= cl_abap_datadescr=>describe_by_name( 'CHAR10' ).
APPEND ls_comp TO lt_comp.
ls_comp-name = 'CARRID'.
ls_comp-type ?= cl_abap_datadescr=>describe_by_name( 'CHAR20' ).
APPEND ls_comp TO lt_comp.
ls_comp-name = 'VBELN'.
ls_comp-type ?= cl_abap_datadescr=>describe_by_name( 'CHAR6' ).
APPEND ls_comp TO lt_comp.
ls_comp-name = 'LIFNR'.
ls_comp-type ?= cl_abap_datadescr=>describe_by_name( 'CHAR6' ).
APPEND ls_comp TO lt_comp.
lo_structtype ?= cl_abap_structdescr=>create( lt_comp ).
lo_tabletype = cl_abap_tabledescr=>create(
p_line_type = lo_structtype
p_table_kind = cl_abap_tabledescr=>tablekind_STD
p_unique = abap_false
p_key = VALUE #( ( NAME = 'MATNR' ) )
p_key_kind = cl_abap_tabledescr=>keydefkind_user ).
CREATE DATA lo_dataref TYPE HANDLE lo_tabletype.
ASSIGN lo_dataref->* TO <lt_table>.
CREATE DATA lo_dataref TYPE HANDLE lo_structtype.
ASSIGN lo_dataref->* TO <ls_table>.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <ls_table> TO <ls_val>.
<ls_val> = '10121'.
ASSIGN COMPONENT 'CARRID' OF STRUCTURE <ls_table> TO <ls_val>.
<ls_val> = 'AA'.
ASSIGN COMPONENT 'VBELN' OF STRUCTURE <ls_table> TO <ls_val>.
<ls_val> = '7432'.
ASSIGN COMPONENT 'LIFNR' OF STRUCTURE <ls_table> TO <ls_val>.
<ls_val> = '567897'.
INSERT <ls_table> INTO TABLE <lt_table>.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <ls_table> TO <ls_val>.
<ls_val> = '10122'.
ASSIGN COMPONENT 'CARRID' OF STRUCTURE <ls_table> TO <ls_val>.
<ls_val> = 'JL'.
ASSIGN COMPONENT 'VBELN' OF STRUCTURE <ls_table> TO <ls_val>.
<ls_val> = '8321'.
ASSIGN COMPONENT 'LIFNR' OF STRUCTURE <ls_table> TO <ls_val>.
<ls_val> = '456789'.
INSERT <ls_table> INTO TABLE <lt_table>.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <ls_table> TO <ls_val>.
<ls_val> = '10120'.
ASSIGN COMPONENT 'CARRID' OF STRUCTURE <ls_table> TO <ls_val>.
<ls_val> = 'BA'.
ASSIGN COMPONENT 'VBELN' OF STRUCTURE <ls_table> TO <ls_val>.
<ls_val> = '6739'.
ASSIGN COMPONENT 'LIFNR' OF STRUCTURE <ls_table> TO <ls_val>.
<ls_val> = '128989'.
INSERT <ls_table> INTO TABLE <lt_table>.
cl_demo_output=>display( <lt_table> ).
Reward points if found helpful.Thanks & Regards,
Preetha.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |