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: 

Field name referenced by field symbol

Former Member
0 Kudos
135

Hi,

I would like to get the field name referenced by a field symbol at rutime. In the code below, besides the type and length of the field, I also would like to get the field names 'AA', 'BB' and 'CC' .

Can you please tell me how I can get this information?

DATA: BEGIN OF g_test,

aa(10) TYPE c,

bb TYPE i,

cc(20) TYPE c,

END OF g_test.

DATA: l_type(20),

l_len TYPE i.

FIELD-SYMBOLS <fs>.

START-OF-SELECTION.

DO 3 TIMES.

ASSIGN COMPONENT sy-index OF STRUCTURE g_test TO <fs>.

DESCRIBE FIELD <fs> TYPE l_type OUTPUT-LENGTH l_len.

WRITE: /5 sy-index, l_type, l_len.

  • Would like output as:

  • 1 AA C 10 instead of 1 C 10

  • 2 BB I 11 instead of 2 I 11

  • 3 CC C 20 instead of 3 C 20

ENDDO.

Regards,

Rao A

1 ACCEPTED SOLUTION

krzysztof_konitz4
Contributor
0 Kudos
61

Hi,

Using your sample structure you can do it using such a code:

DATA: BEGIN OF G_TEST,
        AA(10) TYPE C,
        BB     TYPE I,
        CC(20) TYPE C,
      END OF G_TEST.

TYPE-POOLS: ABAP.

DATA: COMP TYPE LINE OF ABAP_COMPDESCR_TAB.
DATA: STRUCT_REF TYPE REF TO CL_ABAP_STRUCTDESCR.

  STRUCT_REF ?= CL_ABAP_STRUCTDESCR=>DESCRIBE_BY_DATA( G_TEST ).
  LOOP AT STRUCT_REF->COMPONENTS INTO COMP.
    WRITE:/ COMP-NAME, COMP-TYPE_KIND, COMP-LENGTH, COMP-DECIMALS.
  ENDLOOP.

Krzys

2 REPLIES 2

krzysztof_konitz4
Contributor
0 Kudos
62

Hi,

Using your sample structure you can do it using such a code:

DATA: BEGIN OF G_TEST,
        AA(10) TYPE C,
        BB     TYPE I,
        CC(20) TYPE C,
      END OF G_TEST.

TYPE-POOLS: ABAP.

DATA: COMP TYPE LINE OF ABAP_COMPDESCR_TAB.
DATA: STRUCT_REF TYPE REF TO CL_ABAP_STRUCTDESCR.

  STRUCT_REF ?= CL_ABAP_STRUCTDESCR=>DESCRIBE_BY_DATA( G_TEST ).
  LOOP AT STRUCT_REF->COMPONENTS INTO COMP.
    WRITE:/ COMP-NAME, COMP-TYPE_KIND, COMP-LENGTH, COMP-DECIMALS.
  ENDLOOP.

Krzys

0 Kudos
61

Krzysztof,

Thanks a lot!

Regards,

Rao A