Application Development and Automation 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: 
Read only

Pass values from a dynamic table to a structure in a loop

Former Member
0 Likes
823

How can I do this? I assume it is with the assign component instruction but I am not aware on how to do this. I want to loop the dynamic table into the structure to read that value, but since the field symbol does not have a structure and therefore it doesn't have the component I want the value from, it is failing. Any help is appreciated.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
752

Let's assume dyntab is the dynamic internal table, and it contains two fields, one of type C and one of type i.

FIELD-SYMBOLS : <record> type any,

<fld1> type c,

<fld2> type i.

DATA: lr_record type ref to data.

CREATE DATA lr_record like line of dyntab.

ASSIGN lr_record->* to <record> .

ASSIGN COMPONENT 'FLD1' of structure <record> to <fld1>.

ASSIGN COMPONENT 'FLD2' of structure <record> to <fld2>.

LOOP AT dyntab INTO <record>.

     " Use <fld1> and <fld2> just like you would use wa-fld1 and wa-fld2

     WRITE / : <fld1>,<fld2>.

ENDLOOP.

How can I do this? I assume it is with the assign component instruction but I am not aware on how to do this. I want to loop the dynamic table into the structure to read that value, but since the field symbol does not have a structure and therefore it doesn't have the component I want the value from, it is failing. Any help is appreciated.

2 REPLIES 2
Read only

Former Member
0 Likes
753

Let's assume dyntab is the dynamic internal table, and it contains two fields, one of type C and one of type i.

FIELD-SYMBOLS : <record> type any,

<fld1> type c,

<fld2> type i.

DATA: lr_record type ref to data.

CREATE DATA lr_record like line of dyntab.

ASSIGN lr_record->* to <record> .

ASSIGN COMPONENT 'FLD1' of structure <record> to <fld1>.

ASSIGN COMPONENT 'FLD2' of structure <record> to <fld2>.

LOOP AT dyntab INTO <record>.

     " Use <fld1> and <fld2> just like you would use wa-fld1 and wa-fld2

     WRITE / : <fld1>,<fld2>.

ENDLOOP.

Read only

0 Likes
752

Thanks! This helped me.