Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Access Deep Structure in Field Symbol

krisnawijaya98
Discoverer
0 Kudos
1,842

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.

1 ACCEPTED SOLUTION

BhargavaReddy
Active Participant
0 Kudos
1,582

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.

4 REPLIES 4

FredericGirod
Active Contributor
0 Kudos
1,582

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 ?

BhargavaReddy
Active Participant
0 Kudos
1,583

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.

0 Kudos
1,582

Thank you, Bhargava. It meets my requirement.

thkolz
Contributor
0 Kudos
1,582
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.