Skip to Content
-1

how to change the field name dynamically in Loop

Jul 20, 2017 at 10:25 AM

66

avatar image
Former Member

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Ram Burugu Jul 20, 2017 at 12:07 PM
1

You can use field-symbols here:

Here is the link to Help topic on this

https://help.sap.com/viewer/cfae740a0a21455dbe6e510c2d86e36a/7.31.20/en-US/fceb3923358411d1829f0000e829fbfe.html

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.
Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

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

0

Basic programming. Please check the ABAP syntax documentation.

1
Further commenting has been locked.