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: 

how to change the field name dynamically in Loop

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

former_member467951
Participant

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/fceb3923358411d1829f0000e...

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.
3 REPLIES 3

former_member467951
Participant

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/fceb3923358411d1829f0000e...

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.

0 Kudos

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

Basic programming. Please check the ABAP syntax documentation.