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: 

Determine field name of fieldsymbol

Sm1tje
Active Contributor
0 Kudos
131

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,.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
97

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

4 REPLIES 4

former_member598013
Active Contributor
0 Kudos
97

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

0 Kudos
97

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.

Former Member
0 Kudos
98

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

0 Kudos
97

Hi ramiro,

this is the same conclusion and solution I came up with. Thanks anyway.

Kind regards,

Micky.