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
UNTILorWHILEfor conditional iterations. These expressions are used to create (iteratively) the results of any data types using REDUCE or to create rows of internal tables usingNEWorVALUE. The iteration steps can be defined as required.
- Iteration expressions with
INfor table iterations. These expressions are used for table reductions usingREDUCEor table comprehensions usingNEWorVALUE. The iteration steps here evaluate an existing internal table.
Notes
- Any
FORvariants can be combined in a single constructor expression, where they produce nested iterations.
- The reduction operator
REDUCEmust contain at least one iteration expression. The variants of the instance operatorNEWand the value operatorVALUEfor creating internal tables can contain iteration expressions.
- The conditional iterations using
UNTILorWHILEprovide an expression-oriented alternative to the loop statementsDOandWHILE. The same applies to the table iterations usingINand the statementLOOP. The direct use of operand positions by the expression-oriented variants helps to avoid using helper variables. Furthermore, they also enable certain tasks, such as creating values iteratively, to be expressed more concisely and more elegantly.