I am trying to read a dynamic structure and get the value and field names in the structure.
I can get to the values, but I am having a problem getting the field names. I am sure I have done it before (in my past life) but I cannot find an example.
Basicaly, I have a method that is has a struture passed to it as type any.
i the method I have:
note:
???? is the field name of current field being pointed to in the structure.
e_stucture is the structure filled in with values. This can be any struture type.
Method get_do.
field-symbols <fs> type any.
do.
assign component syst-index of structure e_struture
to <fs>.
if syst-subrc <> 0.
exit.
endif.
-->> missing code to get field name.
call method get_field
exporting
fieldname = ????
importing
value = <fs>.
enddo.
Endmethod.
Hi,
It will solve your purpose.Kindly reward points if it helps.
REPORT ZZZ_TEST106 no standard page heading LINE-COUNT 65 .
types: begin of type_item,
f1(3),
f2(3),
f3(3),
f4(3),
end of type_item.
data: lineitems type table of type_item with header line,
fieldlist type table of rstrucinfo with header line.
data: syrepid type sy-repid.
syrepid = sy-repid.
call function 'GET_COMPONENT_LIST'
exporting
program = syrepid
fieldname = 'lineitems'
tables
components = fieldlist.
format color 3.
loop at fieldlist.
write : / fieldlist-compname.
endloop.
Message was edited by: Jayanthi Jayaraman
Hello Glenn
Here is an example that will work on SAP release >= 6.20:
*&---------------------------------------------------------------------* *& Report ZUS_SDN_DYNAMIC_STRUCTURE *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT zus_sdn_dynamic_structure. TYPE-POOLS: abap. DATA: gdo_data TYPE REF TO data, gs_comp TYPE abap_compdescr, " component go_typedescr TYPE REF TO cl_abap_typedescr, go_struct TYPE REF TO cl_abap_structdescr. FIELD-SYMBOLS: <gs_struct> TYPE ANY. PARAMETERS: p_tabnam TYPE tabname DEFAULT 'KNA1'. START-OF-SELECTION. * Dynamic data object of unknown line type CREATE DATA gdo_data TYPE (p_tabnam). ASSIGN gdo_data->* TO <gs_struct>. * Get the runtime type information of the data object CALL METHOD cl_abap_structdescr=>describe_by_data EXPORTING p_data = <gs_struct> RECEIVING p_descr_ref = go_typedescr. * Casting to get the structure instance go_struct ?= go_typedescr. * Output LOOP AT go_struct->components INTO gs_comp. WRITE: / syst-tabix, gs_comp-name. ENDLOOP. END-OF-SELECTION.
Regards
Uwe
Add a comment