2022 Sep 13 4:17 AM
Hello Gurus. I want to ask about accessing deep structure using field symbol. For now, I can accessing the structure only until the Result structure. My requirement is to access until Value structure to get the Token field value. Could anyone help me with this problem? Here is my code :
IF lr_data IS BOUND.
ASSIGN lr_data->* TO FIELD-SYMBOL(<lfs_data>).
ASSIGN COMPONENT 'RESULT' OF STRUCTURE <lfs_data> TO FIELD-SYMBOL(<lfs_results>).
ASSIGN COMPONENT 'VALUE' OF STRUCTURE <lfs_results> TO FIELD-SYMBOL(<lfs_value>).
ENDIF.
2022 Sep 13 7:22 AM
A small correction is that components RESULT and VALUE are pointing to data references, so adjust your code accordingly.
IF lr_data IS BOUND.
ASSIGN lr_data->* TO FIELD-SYMBOL(<lfs_data>).
ASSIGN COMPONENT 'RESULT' OF STRUCTURE <lfs_data> TO FIELD-SYMBOL(<lfs_results_ref>).
ASSIGN <lfs_results_ref>->* TO FIELD-SYMBOL(<lfs_results>).
ASSIGN COMPONENT 'VALUE' OF STRUCTURE <lfs_results> TO FIELD-SYMBOL(<lfs_value_ref>).
ASSIGN <lfs_value_ref>* TO FIELD-SYMBOL(<lfs_value>).
ENDIF.
2022 Sep 13 6:38 AM
What about getting the fieldcatalog of your structure and make a loop on each element and assign dynamicaly the component of the line of the fieldcatalog ?
2022 Sep 13 7:22 AM
A small correction is that components RESULT and VALUE are pointing to data references, so adjust your code accordingly.
IF lr_data IS BOUND.
ASSIGN lr_data->* TO FIELD-SYMBOL(<lfs_data>).
ASSIGN COMPONENT 'RESULT' OF STRUCTURE <lfs_data> TO FIELD-SYMBOL(<lfs_results_ref>).
ASSIGN <lfs_results_ref>->* TO FIELD-SYMBOL(<lfs_results>).
ASSIGN COMPONENT 'VALUE' OF STRUCTURE <lfs_results> TO FIELD-SYMBOL(<lfs_value_ref>).
ASSIGN <lfs_value_ref>* TO FIELD-SYMBOL(<lfs_value>).
ENDIF.
2022 Sep 13 9:29 AM
2022 Sep 13 7:36 AM
DATA:
lr_strucdescr TYPE REF TO cl_abap_structdescr,
s_flight TYPE sflight.
lr_strucdescr ?= cl_abap_typedescr=>describe_by_data( s_flight ).
LOOP AT lr_strucdescr->components INTO DATA(s_components).
ASSIGN COMPONENT s_components-name OF STRUCTURE s_flight TO FIELD-SYMBOL(<fs_field>).
WRITE:/ <fs_field>.
ENDLOOP.