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: 

How to Access field symbols within a structure?

z-mvg
Advisor
Advisor
0 Kudos

Hi all!

I want to declare a field-symbol inside a structure and pass values to it during run-time and append it to the internal table so that field-symbol should contain different values for each row in an internal table. I am not able to find how to pass the values for the field-symbol within the structure.

Please suggest solutions.

2 REPLIES 2

Former Member
0 Kudos

Hello Mohit,

I'm sorry but I'm unable to understand what exactly you're trying to do. You cannot have a field-symbol inside a structure.

However, you can have a data reference variable within a structure. Consider the following declaration -

data : begin of struct,
         carrid  like spfli-carrid,
         connid  like spfli-connid,
         dataref type ref to data,
       end of struct.

Please refer to the F1 documentation on how you can go about it...

Regards,

Anand Mandalika.

0 Kudos

Actually problem is like this , I have to traverse a run time structure which can be deep structure to n level, For that I want to follow the general tree traversal i.e. If it is leaf process it and if it is structure append to internal table and exit.

Input is in form of field symbols which is stored in ir_ret_bef_img type standard table.

DATA : lr_struct_desc_flat TYPE REF TO cl_abap_structdescr

Field-Symbols: <lv_before_field> TYPE any,

<ls_before_line> TYPE any,

<lv_struc_field> TYPE abap_compdescr.

LOOP AT ir_ret_bef_img ASSIGNING <ls_before_line>.

lr_struct_desc_flat ?=

cl_abap_typedescr=>describe_by_data( <ls_before_line> ).

DO.

ASSIGN COMPONENT SY-INDEX OF STRUCTURE <ls_before_line>

TO <lv_before_field>.

IF sy-subrc NE 0.

exit.

ENDIF.

READ TABLE lr_struct_desc_flat->COMPONENTS INDEX

lv_count_deep ASSIGNING <lv_struc_field>.

IF sy-subrc NE 0.

exit.

ENDIF.

IF <lv_struc_field>-TYPE_KIND = 'u'.

lr_struct_desc_deep ?=

cl_abap_typedescr=>describe_by_data(<before_field>).

str-fi = lr_struct_desc_deep.

-


> In this place i want to assign <lv_before_field> to a work area and then append it to internal table so that i can run a loop on internal table. I need help that how to declare work area for that and how can i assign value.

append str to tt.

ENDIF.

lv_count_deep = lv_count_deep + 1.

ENDDO.