2008 Oct 30 5:39 PM
Hi all,
how can I retrieve the fieldname of a field-symbol at runtime.
I have the following statement:
do.
assign component sy-index of structure 'structure' to <field>.
Now I want to determine if the name of the field to which this field-symbol is pointing to.
Only in case the name of the field starts with ' ZZ', I need to do something.
enddo,.
2008 Oct 30 5:50 PM
This is the closer I can find
TYPE-POOLS: abap.
DATA: BEGIN OF struct,
one,
two,
three,
four,
END OF struct.
FIELD-SYMBOLS <fs> TYPE ANY.
DATA: obj TYPE REF TO cl_abap_structdescr.
DATA: comp_wa TYPE abap_compdescr.
obj ?= cl_abap_typedescr=>describe_by_data( struct ).
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE struct TO <fs>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
READ TABLE obj->components INTO comp_wa INDEX sy-index.
WRITE / comp_wa-name.
ENDDO.
I don't think you can analize the name of the variable the <fs> is pointing, only you can find the name of the components in an structure
2008 Oct 30 5:46 PM
Hi Micky,
Do it in this way.
FIELD-SYMBOLS :
<fs1> TYPE ANY.
CONCATENATE 'IT_FINAL-DMBTR' l_tabix INTO l_field_qty.
ASSIGN: COMPONENT 'DMBTR' OF STRUCTURE it1_mseg TO <fs>.
ASSIGN: l_field_qty TO <fs1>.
Thanks,
Chidanand
2008 Oct 30 7:16 PM
This is not what I was looking for, since I don't know the name of the field. On the contrary, it is the name of the field I want to determine.
2008 Oct 30 5:50 PM
This is the closer I can find
TYPE-POOLS: abap.
DATA: BEGIN OF struct,
one,
two,
three,
four,
END OF struct.
FIELD-SYMBOLS <fs> TYPE ANY.
DATA: obj TYPE REF TO cl_abap_structdescr.
DATA: comp_wa TYPE abap_compdescr.
obj ?= cl_abap_typedescr=>describe_by_data( struct ).
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE struct TO <fs>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
READ TABLE obj->components INTO comp_wa INDEX sy-index.
WRITE / comp_wa-name.
ENDDO.
I don't think you can analize the name of the variable the <fs> is pointing, only you can find the name of the components in an structure
2008 Oct 30 7:15 PM
Hi ramiro,
this is the same conclusion and solution I came up with. Thanks anyway.
Kind regards,
Micky.