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: 

Dynamic Field Symbol assignment for the FOR loop

0 Kudos
651

Hello there ,

I'm trying to build the internal table from the dynamic table using FOR loop or want to know whether its possible or not

Data in the dynamic table

<gt_data>

Since I became an avid fan of the constructor expressions Value, Cond, etc I tried building this with the new syntax.

I want to assign the above data into new internal table which has fixed structure define using FOR syntax .

GT_TABLE should contain following data from the above dynamic internal table.

P.S -

I'm aware I can use the syntax as

LOOP

ASSIGN 'COMPONENT' OF STRUCTURE .....

But I would like to know whether the same can be achieved with FOR loop or not.

Thanks

Shashank

1 ACCEPTED SOLUTION

ThorstenHoefer
Active Contributor
533

Hi,

have you tried class cl_abap_corresponding?

https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abencl_abap_corr_itab_abexa.htm

Regards
Thorsten

4 REPLIES 4

Sandra_Rossi
Active Contributor
533

It depends which ABAP version you are using. I remember in a blog post by a SAP expert, new expressions like OREF->(COMPNAME) in latest versions, maybe we also have STRUCT-(NAME)...

ThorstenHoefer
Active Contributor
534

Hi,

have you tried class cl_abap_corresponding?

https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abencl_abap_corr_itab_abexa.htm

Regards
Thorsten

lenapadeken
Product and Topic Expert
Product and Topic Expert
533

sandra.rossi STRUCT-(NAME) is also available (Docu).

Sandra_Rossi
Active Contributor
0 Kudos
533

As Lena said, STRUCT-(NAME) can be used only with ASSIGN, but ASSIGN can't be directly used in a constructor expression, it means that you must use the workaround of calling a method equivalent to ASSIGN, which can be one of CL_ABAP_CORRESPONDING methods as Thorsten suggested.