2005 Jul 03 2:15 PM
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
2005 Jul 03 6:37 PM
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
2005 Jul 03 6:37 PM
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
2005 Jul 04 6:00 AM