Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Get name of structure field

Hi Gurus!

I need get a string with field name. For example:

TYPES: BEGIN OF t_mara,

               material TYPE matnr,

               plant      TYPE werks,

             END OF t_mara.

I can get field names of structures using:

DATA: lr_rtti_struc TYPE REF TO cl_abap_structdescr.

DATA: lt_comp       TYPE cl_abap_structdescr=>component_table.

DATA: ls_comp       LIKE LINE OF lt_comp.

DATA: ls_mara       TYPE t_mara.

lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( ls_mara ). " Get the description of the data

lt_comp = lr_rtti_struc->get_components( ). "Get the fields of the structure

loop at lt_comp into ls_comp.

WRITE:/ ls_comp-name. " Write the column names

endloop.

With this code the result will be:

MATERIAL

PLANT

But i need get only description for a field as:

  DATA: lv_element TYPE REF TO cl_abap_datadescr.

  TRY.

      lv_element ?= cl_abap_datadescr=>describe_by_data( lw_mara-material ).

    CATCH cx_sy_move_cast_error.

  ENDTRY.

I get only description for the type of field, in this case "matnr". All class cl_abap_* only return data about types...


Thanks and regards,

Jose

Former Member
Not what you were looking for? View more on this topic or Ask a question