How to use the while Statement in SAP ABAP
The while statement is a looping mechanism similar to do.
Syntax for the while Statement
The following is the syntax for the while statement.
while exp [ vary f1 from s-c1 next s-c2 [ vary f2 from s2-c1 next s2-c2 ... ]
—
[ exit. ]
—
endwhile.
where:
* exp is a logical expression.
* s is a field string having the components c1 and c2.
* f1 is a variable. The components of s must be able to be converted to the data type and length of f1.
* … represents any number of complete vary clauses.
* — represents any number of lines of code.
The following points apply:
* while loops can be nested an infinite number of times and also be nested within any other type of loop.
* exit prevents further loop processing and exits immediately out of the current loop. Processing continues at the next executable statement after endwhile.
* Within the loop, sy-index contains the current iteration number. After endwhile,
sy-index contains the value it had before entering the loop. With nested while loops, sy-index contains the iteration number of the loop in which it is used.
* endwhile always copies the value of f1 back into the sending component.
* On a while statement containing a logical expression and a varying addition, the logical expression is evaluated first.
while is very similar to do. Here, it is used to place an equal number of dashes on either side of a string.
Popularity: 6% [?]






