Skip to Content
avatar image
Former Member

Get field names of an internal structure

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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Dec 11, 2008 at 03:28 PM

    BUMP

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      For future reference, answer is in thread get-the-field-name-of-a-internal-table-or-structur

      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.

  • avatar image
    Former Member
    Dec 11, 2008 at 03:49 PM

    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.
    

    Add comment
    10|10000 characters needed characters exceeded