07-20-2017 11:25 AM
Dear All,
I have to change the field name dynamically in the loop. Database Name is PA0027 having fields PSP01, PSP02, PSP03 up to PSP25. I want to pass the data to these fields in loop and update.
Following is my Code.
LOOP AT IT_FINAL INTO WA_FINAL
MOVE WA_FINAL-WBS TO WA_PA0027-PSP01.
ENDLOOP.
In above code I have to change the Field name in each loop pass that WA_PA0027-PSP01, then in next loop WA_PA0027-PSP02 then next loop pass WA_PA0027-PSP03. So please suggest me how to change the field name dynamically in Loop.
Waiting for reply.
Thank You
Regards
07-20-2017 1:07 PM
You can use field-symbols here:
Here is the link to Help topic on this
And a code snippet. Please note that I did not take care of performance etc. into conderation, I just want to educate you on use of field-symbols.
FIELD-SYMBOLS <fs_field> TYPE any.
DATA lv_field TYPE char5.
DATA lv_counter TYPE n LENGTH 2.
LOOP AT lt_final INTO ls_final.
DO 10 TIMES.
lv_counter = sy-index.
lv_field = 'PSP' && lv_counter.
ASSIGN COMPONENT lv_field OF STRUCTURE ls_final TO <fs_field>.
<fs_field> = '123'.
ENDDO.
"modify record here
ENDLOOP.
07-20-2017 1:07 PM
You can use field-symbols here:
Here is the link to Help topic on this
And a code snippet. Please note that I did not take care of performance etc. into conderation, I just want to educate you on use of field-symbols.
FIELD-SYMBOLS <fs_field> TYPE any.
DATA lv_field TYPE char5.
DATA lv_counter TYPE n LENGTH 2.
LOOP AT lt_final INTO ls_final.
DO 10 TIMES.
lv_counter = sy-index.
lv_field = 'PSP' && lv_counter.
ASSIGN COMPONENT lv_field OF STRUCTURE ls_final TO <fs_field>.
<fs_field> = '123'.
ENDDO.
"modify record here
ENDLOOP.
07-24-2017 2:30 PM
Great yaar .. ..Thanks for your help.
cheers 🙂
One more question I would like to ask you is that,
I need to round off the value after decimal 2 .. for example .. value is 12.578 need to get like 12.58 if 3 rd digit is greater than 5.
if value is 12.3333 no need to change only get 12.33
Hope my question is well addressed.
Thanks,
sham
07-25-2017 6:28 AM