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.
	  WHEN ‘COMPONENT_NAME’.
** write some code here 
    
    ENDCASE.	
  ENDLOOP.  

 

ABOUT Ekrem Güngörmez

https://tr.linkedin.com/in/ekremgungormez

COMMENTS

comments powered by Disqus