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

Changing Field Name Dynamically

Former Member
0 Likes
877

Dear All,

I have to change the field name dynamically in the loop. Database Name is PA9002 having fields ZFAMSA1, ZFAMSA2, ZFAMSA3 up to ZFAMSA10. I want to pass the data to these fields in loop and update.

Following is my Code.

LOOP AT GT_PA0021 INTO GS_PA0021

MOVE GA_PA0021-SUBTY TO P9002-FAMSA1.

ENDLOOP.

In above code I have to change the Field name in each loop pass that P9002-FAMSA1, then in next loop P9002-FAMSA2 then next loop pass P9002-FAMSA3. So please suggest me how to change the field name dynamically in Loop.

Waiting for reply.

Thank You

Regards

Mangesh

5 REPLIES 5
Read only

Former Member
0 Likes
732

i'm not sure if u can use a variable as fieldname . One thing u can do is to use a switch case with sy-tabix or some count variable.

Read only

0 Likes
732

Dear Kartik,

I tried many option but then decided to Post Message to SDN. Yet my problem is not solved.

Regards

Mangesh

Read only

0 Likes
732

try field symbols

Read only

Former Member
0 Likes
732

Check this if it works:

FIELD-SYMBOLS:

<field1> TYPE ANY,

<field2> TYPE ANY,

<field3> TYPE ANY,

<line> TYPE ANY.

Assign P9002 to <line>.

LOOP AT GT_PA0021 INTO ASSIGNING GS_PA0021.

If sy-tabix = 1.

ASSIGN COMPONENT 1 OF STRUCTURE <myline> TO <field1>.

Assign GA_PA0021-SUBTY to <field1>.

elseif sy-tabix = 2.

ASSIGN COMPONENT 2 OF STRUCTURE <myline> TO <field2>.

Assign GA_PA0021-SUBTY to <field2>.

Endif.

ENDLOOP.

Edited by: Neha Shukla on Dec 13, 2008 6:57 PM

Read only

Former Member
0 Likes
732

u can try like this

loop at gt_pa2001 into gs_pa2001

case sy-tabix

when 1.

Use ur note for first famsa

similarly when 2 .

Use for second and so on