Hi Christian,
Thanks for your reply. But I have some doubts as well. Below I have highlighted them.
" define the structure's first component MATERIAL
gs_component-name = 'MATERIAL'.
" create a type description for ABAP dictionary type MATNR (material number) - casting required
gs_component-type ?= cl_abap_elemdescr=>describe_by_name( 'MATNR' ).
APPEND gs_component TO gt_compontents.
How can we write component name as 'MATERIAL' and component type as MATNR when do not know component name and type. Same applies to the below component type as well. We will come to know the components at run time.
gs_component-name = 'MATTEXT'.
" create a type description for ABAP dictionary type MAKTX (material short text) - casting required
gs_component-type ?= cl_abap_elemdescr=>describe_by_name( 'MAKTX' ).
APPEND gs_component TO gt_compo, ntents.
" create structure's type definition from the component table
lo_dynamic_struct = cl_abap_structdescr=>create( gt_compontents ).
" now create memory structure to actually store the data