Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the Components of a structure?

Former Member

Hallo,

how can I get the names of the components of a structure in an ABAP program?

Thank you,

Manuel

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate

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

9 REPLIES 9

Former Member
0 Kudos

structurename-componentname

Vijay
Active Contributor
0 Kudos

hi

components of the structure is nothing but the fields of structure.

you can check the fields of the standard stuctures in se11.

regards

vijay

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Feb 6, 2008 2:47 PM

Former Member
0 Kudos

Do you want to get the components of a structure dynamically at run time?

Former Member
0 Kudos

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

Former Member
0 Kudos

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

RichHeilman
Developer Advocate
Developer Advocate

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

former_member402878
Discoverer
0 Kudos

This message was moderated.