How to Get Component List of Structure Dynamically

The code below will be enough to get components of a/dynamic structure. I used field symbol in my example, if the structure’s name is known it can be given to the “describe_by_data” method directy.   


  DATA: ls_comp TYPE abap_componentdescr,
        ls_stru TYPE REF TO cl_abap_structdescr,
        lt_comp TYPE STANDARD TABLE OF abap_componentdescr WITH KEY name.

  FIELD-SYMBOLS:  <lfs_first>.

***Assign field symbol here
  ls_stru ?= cl_abap_typedescr=>describe_by_data( <lfs_first> ).
  lt_comp = ls_stru->get_components( ).

  LOOP AT ut_comp INTO ls_comp.
    CASE ls_comp-name.
** write some code here 


ABOUT Ekrem Güngörmez


comments powered by Disqus