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

-DO_WHILE_VARY_NOT_IN_RANGE - When using while endwhile

Former Member
0 Likes
1,043

Hi all ,

ex : I need to print values 23 24 25 26 preferably integers using while and endwhile looping.

when we use do enddo condition the loop iterates 22 times to reach the processing logic .

Using while endwhile we reach the condition 23 in the logical expression , im doing it but im getting one dump when i enter ranges value.

somewhere im doing a mistake .. need hints ..

Thanks.

  
data : int type i.
RANGES SELTAB FOR INT.
SELTAB-SIGN = 'I'.
SELTAB-OPTION = 'EQ'.
SELTAB-LOW = lv_low.
SELTAB-HIGH = lv_high.
append seltab.
 while ( l_val <= lv_high ) vary l_Val from seltab-low next seltab-high range seltab.

 endwhile .

here lv_low and lv_high are the limits of my logic ..

Br,

Vijay.

6 REPLIES 6
Read only

Former Member
0 Likes
871
data : int type i.
RANGES SELTAB FOR INT.
SELTAB-SIGN = 'I'.
SELTAB-OPTION = 'BT'.   <<-------- Check adding this.
SELTAB-LOW = lv_low.
SELTAB-HIGH = lv_high.
append seltab.
 while ( l_val <= lv_high ) vary l_Val from seltab-low next seltab-high range seltab.
 
 endwhile

.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
871

The while vary is similar to the do varying syntax, the from/next argument are objects (variables) not values, with your syntax

In a DO VARYING/WHILE VARY

- first iteration - l_val points on field seltab-low

- second iteration - l_val points on field seltab-high

- next iterations - l_val is lost somewhere in the program memory

Usage :

suppose you have a structure with similar fields FIELD01, FIELD02, ... FIELD99

in each DO or WHILE iteration the varying pointer is assigned to FIELD01, then FIELD02, etc.

You really don't need this option to fulfil your requirement.

l_value = l_low
WHILE l_value LE l_high.
" process value
  ADD 1 to l_value.
ENDWHILE 

The RANGE option limits the memory area allowed to pointers, so no unwanted errors may arise.

Regards,

Raymond

Read only

0 Likes
871

Dear Raymond ,

Thanks for your reply .

// next iterations - l_val is lost somewhere in the program memory

Infact the problem is solved if you are using the code to add 1 value inside the while logic. My attempt was to get rid of those

extra iterations .

  
l_value = l_low
WHILE l_value LE l_high.
" process value
  ADD 1 to l_value.
       if l_value between desired range . "processing block
         then do something here .. 
      endif.
ENDWHILE 

Now using the above we reach to the processing block only after l_value crossed 22 ref to my earlier example. SO there is no go around to land directly .. just curious ..

Thanks for your time ..

Br,

Vijay

Read only

0 Likes
871

With this


l_value = l_low
WHILE l_value LE l_high.
       if l_value between desired range . "<- no check here needed
        ...
      endif.
  ADD 1 to l_value.
ENDWHILE 

...as you are starting the iteration from lowest desired range value up to highest one, so this is the range exactly you need (providing the iteration has to take place via each integer) i.e.


start = 22. 
after 1) 23
after 2) 24
after 3) 25
...
end = 27.

So the problem relating to unwanted iterations is not applicable I think.

Regards

Marcin

Read only

MarcinPciak
Active Contributor
0 Likes
871

I think this won't work as you expect. The documenation says

The addition RANGE specifies the memory area that can be processed with the addition VARYING . After RANGE, you can specify an elementary data object range of the type c, n,x, or a structure .

I think the RANGE is ambigous here. They don't mean the RANGE table but the rather a memory restriction of the processing.

Moreover if you look closer to your code you would see that you are in fact addressing a table header not a table itself, so no ranges applies per se.

The purpose of this statement is different than you expect. You will have to think of other approach.

Regards

Marcin

Read only

0 Likes
871

To explain the RANGE, suppose you have a structure STRUCT with subfields FIELD01, FIELD02, ... FIELD05, using a RANGE STRUCT limits the vary/varying FROM STRUCT-FIELD01 NEXT STRUCT-FIELD02 to those subfields, and forbid the program to point to a 6th field, which don't belong to the structure.

No relation with a [DATA - RANGE OF |http://help.sap.com/abapdocu_70/en/ABAPDATA_RANGES.htm].

Check documentation at [WHILE - VARY |http://help.sap.com/abapdocu_70/en/ABAPWHILE_VARY.htm] and [DO - VARYING |http://help.sap.com/abapdocu_70/en/ABAPDO_VARYING.htm] (obsolete)

Regards,

Raymond