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: 

Get field names of an internal structure

Former Member
0 Kudos

Hi,

In my program, I have a structure created via begin-of/end-of.

A table is based on this structure and later on, I use a macro that deals with the field names and values.

I'd like to make the macro dynamic, in that it gets the table field names with hardcoded values.

Is there anyway to get the names of my structure field names via an FM or through coding?

Thanks,

John

3 REPLIES 3

Former Member

BUMP

0 Kudos

For future reference, answer is in thread

data: gs_t001 type t001.

data: go_struct type ref to cl_abap_structdescr,

gt_comp type abap_component_tab,

gs_comp type abap_componentdescr.

start-of-selection.

go_struct ?= cl_abap_typedescr=>describe_by_data( gs_t001 ).

gt_comp = go_struct->get_components( ).

loop at gt_comp into gs_comp.

write: / gs_comp-name.

endloop.

Former Member

Two ways:

1) If you define your structure based on a data dictionary structure, you can use function module DDIF_TABL_GET to get the structure field names.

2) In NetWeaver version 6.0 and above, you can use Run Time Type Services (RTTS) classes for this purpose.

Here is sample code for RTTS:


data: BEGIN OF wa,
        field1 type c,
        field2 type d,
        field3 type i,
      END OF wa.
DATA: r_descr TYPE REF TO cl_abap_structdescr,
      wa_comp TYPE abap_compdescr.

r_descr ?= cl_abap_typedescr=>describe_by_data( wa ).
LOOP AT r_descr->components INTO wa_comp.
  WRITE:/ wa_comp-name.
ENDLOOP.