02-06-2008 1:07 PM
Hallo,
how can I get the names of the components of a structure in an ABAP program?
Thank you,
Manuel
02-06-2008 1:19 PM
You can use the RTTS for this.
type-pools: abap.
DATA: ls_components TYPE abap_compdescr.
DATA: lo_strucdescr TYPE REF TO cl_abap_structdescr.
DATA: ls_t001 TYPE t001.
lo_strucdescr ?= cl_abap_typedescr=>describe_by_data( ls_t001 ).
LOOP AT lo_strucdescr->components INTO ls_components.
WRITE:/ ls_components-name.
ENDLOOP.
Regards,
Rich Heilman
02-06-2008 1:10 PM
02-06-2008 1:12 PM
02-06-2008 1:15 PM
Do you want to get the components of a structure dynamically at run time?
02-06-2008 1:18 PM
1. se11 with the structure name witin DATATYPE option.
2. If you want to watch the fields within the abap editor write structure-field and double-click it.
example: write RC29P-STLKZ and doble-click it.
<REMOVED BY MODERATOR>
best regards,
Reb
Edited by: Alvaro Tejada Galindo on Feb 6, 2008 2:52 PM
02-06-2008 1:18 PM
Hi
You can give Data Element from ABAP Dictionary as a Component Type.
<REMOVED BY MODERATOR>
Edited by: Alvaro Tejada Galindo on Feb 6, 2008 2:53 PM
02-06-2008 1:19 PM
You can use the RTTS for this.
type-pools: abap.
DATA: ls_components TYPE abap_compdescr.
DATA: lo_strucdescr TYPE REF TO cl_abap_structdescr.
DATA: ls_t001 TYPE t001.
lo_strucdescr ?= cl_abap_typedescr=>describe_by_data( ls_t001 ).
LOOP AT lo_strucdescr->components INTO ls_components.
WRITE:/ ls_components-name.
ENDLOOP.
Regards,
Rich Heilman
02-06-2008 1:32 PM
Hi,
try this code.
data:BEGIN OF str,
matnr type mara-matnr,
ersda type mara-ersda,
END OF str.
DATA: lr_rtti_struc TYPE REF TO cl_abap_structdescr.
DATA: lt_comp TYPE cl_abap_structdescr=>component_table.
DATA: ls_comp LIKE LINE OF lt_comp.
lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( str ). " Get the description of the data
lt_comp = lr_rtti_struc->get_components( ). "Get the fields of the structure
loop at lt_comp into ls_comp.
WRITE:/ ls_comp-name. " Write the column names
endloop.
rgds,
bharat.
02-07-2008 6:51 AM
Hello,
Try the following code.
DATA : components LIKE rstrucinfo OCCURS 0 WITH HEADER LINE. " List of components
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
program = sy-repid
fieldname = < STRUCTURE NAME >
TABLES
components = components.
The components table will return all the components of the <structure>.
Hope this will be helpful.
Regards,
Pranali
06-30-2016 4:26 AM