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

Change Variable Name

Former Member
0 Likes
601

Hi

I have a requirement where I want to loop 10 times over an internal table, but passing the same value to all.

For ex.

Do 10 times.
Read table itab into wa index sy-index.
  if sy-subrc = 0.
    var1 = wa-field.
  endif.
Enddo.

My requirement is to change this VAR1 to VAR2 in next iteration, then to VAR3.......upto VAR10 for every iteration of loop.

Regards

Kapil

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
516

try this .

declare variable VAR1 to VAR 10 .

DATA:  LV_FIELDNAME(9)   TYPE C,
       LV_PREFIX(3)      TYPE C VALUE 'VAR'
       LV_LINE_NUMBER(2) TYPE N .

FIELD-SYMBOLS : <FS_GLOBAL_VARIABLE>.


Do 10 times.

  ADD 1 TO LV_LINE_NUMBER.
  
  CONCATENATE LV_PREFIX 
              LV_LINE_NUMBER
         INTO LV_FIELDNAME.

  ASSIGN (LV_FIELDNAME) TO <FS_GLOBAL_VARIABLE>.
  
  Read table itab into wa index sy-index.
   
   if sy-subrc = 0.
     <FS_GLOBAL_VARIABLE> = wa-field.
   ENDIF.

ENDDO

Jitendra

2 REPLIES 2
Read only

Former Member
0 Likes
517

try this .

declare variable VAR1 to VAR 10 .

DATA:  LV_FIELDNAME(9)   TYPE C,
       LV_PREFIX(3)      TYPE C VALUE 'VAR'
       LV_LINE_NUMBER(2) TYPE N .

FIELD-SYMBOLS : <FS_GLOBAL_VARIABLE>.


Do 10 times.

  ADD 1 TO LV_LINE_NUMBER.
  
  CONCATENATE LV_PREFIX 
              LV_LINE_NUMBER
         INTO LV_FIELDNAME.

  ASSIGN (LV_FIELDNAME) TO <FS_GLOBAL_VARIABLE>.
  
  Read table itab into wa index sy-index.
   
   if sy-subrc = 0.
     <FS_GLOBAL_VARIABLE> = wa-field.
   ENDIF.

ENDDO

Jitendra

Read only

0 Likes
516

Thanks Jitendra.