ABAP Keyword Documentation → ABAP - Reference → Program Flow Logic → Iteration Expressions
FOR - Iteration Expressions
Other versions:
7.31 | 7.40 | 7.54
Syntax
... REDUCE|
NEW|
VALUE type( ... FOR
... UNTIL|WHILE ...|... IN ... ... ) ...
Effect
The language element FOR
introduces an
iteration expression as a subexpression in
constructor expressions
with the reduction operator REDUCE
and in the variants of the instance operator
NEW and the value operator VALUE
for creating internal tables.
There are two main variants of iteration expressions:
- Iteration expressions with
UNTIL
orWHILE
for conditional iterations. These expressions are used to create (iteratively) the results of any data types using REDUCE or to create rows of internal tables usingNEW
orVALUE
. The iteration steps can be defined as required.
- Iteration expressions with
IN
for table iterations. These expressions are used for table reductions usingREDUCE
or table comprehensions usingNEW
orVALUE
. The iteration steps here evaluate an existing internal table.
Notes
- Any
FOR
variants can be combined in a single constructor expression, where they produce nested iterations.
- The reduction operator
REDUCE
must contain at least one iteration expression. The variants of the instance operatorNEW
and the value operatorVALUE
for creating internal tables can contain iteration expressions.
- The conditional iterations using
UNTIL
orWHILE
provide an expression-oriented alternative to the loop statementsDO
andWHILE
. The same applies to the table iterations usingIN
and the statementLOOP
. The direct use of operand positions by the expression-oriented variants helps to avoid using auxiliary variables. Furthermore, they also enable certain tasks, such as creating values iteratively, to be expressed more concisely and more elegantly.