08-31-2007 1:34 PM
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
08-31-2007 1:37 PM
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.
08-31-2007 1:37 PM
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.
08-31-2007 1:51 PM
09-08-2014 12:47 PM
Nice solution ! (still usefull even after years)
Thanks for that help,
Have a nice day,
Paskalo.
08-31-2007 1:41 PM
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