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: 

ABAP HR: DO VARYING Statement Alternate

Former Member
0 Kudos

DATA: GWA_0008 TYPE PA0008,

LGART TYPE PA0008-LGA01,

BETRG TYPE PA0008-BET01.

SELECT SINGLE * FROM PA0008 INTO GWA_0008.

DO 40 TIMES

VARYING LGART FROM GWA_0008-LGA01 NEXT GWA_0008-LGA02

VARYING BETRG FROM GWA_0008-BET01 NEXT GWA_0008-BET02.

" CODE

ENDDO.

as 'do varying' is obselete now, what is the alternate for this statement?

7 REPLIES 7

rainer_hbenthal
Active Contributor
0 Kudos

I cant see that do varying is obsolete now. Where did you read that? I cant find anything about that in the online help.

JozsefSzikszai
Active Contributor
0 Kudos

this is what you need: ASSIGN + INCREMENT :

http://help.sap.com/abapdocu/en/ABAPASSIGN_MEM_AREA_DYNAMIC_DOBJ.htm#!ABAP_ALTERNATIVE_3@3@

Rainer: it is obsolate in Unicode environemnt

former_member181995
Active Contributor
0 Kudos

But you can still use these in your program since you are take care of these exceptions cause i have still DO VARYING Statements in ECC:

Cause: Impermissible access to tables, strings, field or object references within the range specified by the RANGE addition. 
Runtime Error: DO_WHILE_VARY_ILLEGAL_ACCESS 

Cause: Access to data outside the range specified by the RANGE addition. 
Runtime Error: DO_WHILE_VARY_NOT_IN_RANGE

for more help jusr use F1 on DO VARYING there is option there with INCREMENT .

former_member188685
Active Contributor
0 Kudos

i don't like do varying logic, i generally go for Field-symbols logic inside do enddo.

Former Member
0 Kudos

Yes: alternate is by the use of ASSIGN + INCREMENT.

But may i have an replacement code for DO VARYING mentioned above, using ASSIGN + INCREMENT.

MarcinPciak
Active Contributor
0 Kudos

Do like this:


data: s_lgart(14) type c value 'GWA_0008-LGA  ',
      s_betrg(14) type c value 'GWA_0008-BET  ',
      index(2) type n.

field-symbols: <fs_lgart> TYPE PA0008-LGA01,
              <fs_betrg> TYPE PA0008-BET01.


do 40 times.
    index = sy-index.    "01, 02, 03, 04...
    s_lgart+12(2) = index.    "GWA_0008-LGA01, GWA_0008-LGA02 ...
    s_betrg+12(2) = index.   "GWA_0008-BET01, GWA_0008-BET02...

    assing s_lgart to <fs_betrg>.      
    assing s_betrg to <fs_lgart>.
    "<fs_betrg> and <fs_lgart> now store respective values LGA01, BET01 (in first loop), LGA02, BET02 (in second) and so on...
    "perform your action 
enddo.

Former Member
0 Kudos

Hi Marcin,

It will come like this

DATA: S_LGART(5) TYPE C VALUE 'LGA ',

S_BETRG(5) TYPE C VALUE 'BET ',

INDEX(2) TYPE N.

FIELD-SYMBOLS: <FS_LGART>,

<FS_BETRG>.

DO 40 TIMES.

INDEX = SY-INDEX.

S_LGART+3(2) = INDEX.

S_BETRG+3(2) = INDEX.

ASSIGN COMPONENT S_LGART of STRUCTURE GWA_0008 TO <FS_BETRG>.

ASSIGN COMPONENT S_BETRG of STRUCTURE GWA_0008 TO <FS_LGART>.

ENDDO.

But I want an alternate using Assign with Increment statement.