‎2010 May 05 10:35 AM
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.
‎2010 May 05 10:48 AM
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.
‎2010 May 05 10:50 AM
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
‎2010 May 05 10:58 AM
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
‎2010 May 05 11:30 AM
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
‎2010 May 05 10:56 AM
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
‎2010 May 05 11:04 AM
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