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 structure component name?

MarcinPciak
Active Contributor
0 Kudos

Hi,

This is my code:

data: wa_outtab type t_mytype.

field-symbols <fs_componet> type any.

do.

assign component sy-index

of structure wa_outtab to <fs_component>

if sy-subrc <> 0.

exit.

endif.

write / <fs_component>.

enddo.

My question is. How can I display name of <fs_component> it is pointing to (names of the fields in wa_outtab instead of its values)?

Please help.

Reagards

1 ACCEPTED SOLUTION

Former Member

HI,

do like this.

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( <b>wa_outtab</b> ). " 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.

<b>reward if helpful</b>

rgds,

bharat.

4 REPLIES 4

Former Member

HI,

do like this.

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( <b>wa_outtab</b> ). " 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.

<b>reward if helpful</b>

rgds,

bharat.

0 Kudos

thx a lot:)

0 Kudos

Nice solution ! (still usefull even after years)

Thanks for that help,

Have a nice day,

Paskalo.

uwe_schieferstein
Active Contributor
0 Kudos

Hello Marcin

You could try the following coding:

  DATA:
    ld_name           TYPE string,
    ldo_data           TYPE REF TO data,
    lo_typedescr     TYPE REF TO cl_abap_typedescr.


  GET REFERENCE OF <fs_component> INTO ldo_data.
  lo_typedescr = CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA_REF( ldo_data ).

  ld_name = lo_typedescr->get_relative_name( ).
" Perhaps other methods of CL_ABAP_TYPEDESCR are more useful...

Regards

Uwe