‎2008 Dec 13 11:35 AM
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
‎2008 Dec 13 12:09 PM
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.
‎2008 Dec 13 12:37 PM
Dear Kartik,
I tried many option but then decided to Post Message to SDN. Yet my problem is not solved.
Regards
Mangesh
‎2008 Dec 13 12:57 PM
‎2008 Dec 13 1:26 PM
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
‎2008 Dec 13 2:30 PM
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