Ansicht
Dokumentation

ABENFOR_CONDITIONAL - FOR CONDITIONAL

ABENFOR_CONDITIONAL - FOR CONDITIONAL

BAL Application Log Documentation   CPI1466 during Backup  
This documentation is copyright by SAP AG.
SAP E-Book

FOR, Conditional Iteration

... FOR var = rhs $[THEN expr$] UNTIL$|WHILE log_exp $[let_exp$] ...

Effect

This syntax form of an iteration expression executes a conditional iteration.

  • If it is used in a constructor expression with the reduction operator REDUCE, the reduction result is created in the iteration steps.
  • If it is used in a constructor expression with the instance operator NEW or with the value operator VALUE for internal tables, new table lines are created in the iteration steps and inserted into the tabular result.

The parameters and arguments of the iteration expression must be specified as follows:

  • First, a local helper variable var must be declared as an iteration variable and assigned a start value rhs with =. The same applies to the namespace and visibility of var as to the helper fields declared in a LET expression. The syntax of the declaration is exactly the same as in a LET expression and it follows the rules that apply here.
  • The next position depends on the data type of the iteration variable var:
  • If the iteration variable var does not have a numeric data type and is not of type d or t, an expression expr must be specified after THEN. The result of this expression can be converted into a data type of var. The expression is calculated for every iteration and its result is assigned to the iteration variable var. This is a general expression position.

  • If the iteration variable var has a numeric data type, or is of type d or t, THEN expr is optional. If THEN expr is not specified explicitly, THEN var + 1 is added implicitly or the value of the iteration variable is increased by 1 for every iteration.

  • Afterwards, a termination condition log_exp must be specified after UNTIL or WHILE. log_exp is any logical expression whose operands can be any data objects visible at this position and any calls possible here.
  • If the termination condition is specified after UNTIL, the logical expression log_exp is evaluated after every iteration step. If the result of the logical expression is true, the iteration is ended. At least one iteration step is executed.

  • If the termination condition is specified after WHILE, the logical expression log_exp is evaluated after every iteration step. If the result of the logical expression is false, the iteration is terminated. If the result of the logical expression is already false before the first iteration step, no iteration steps are executed.

  • An optional LET expression let_exp can be specified at the end to define local helper fields. The helper fields are filled in every iteration step and can be used to construct the result.

The variables declared in FOR expressions are local. The local data of all outer FOR expressions can be used when their values are set. The iteration variable and any helper variables can be used after the FOR expression, either in additional subexpressions or to construct the result.

The system field sy-index is not set by a FOR expression.

Notes

  • Usually, the expression expr (after THEN) and the termination condition log_exp after UNTIL or WHILE depend on the iteration variable var, but this not a prerequisite. The value of the iteration variable or the termination condition can also be determined in other ways. Status changes, for example, can be queried using method calls.
  • Usually, a termination condition after UNTIL is preferable to a termination condition after WHILE in all cases where the termination condition does not have to be checked before the first iteration step.
  • In many cases, iteration expressions for conditional iterations can replace DO and WHILE loops, which construct values and internal tables.
  • Multiple sequential FOR expressions with different variants, including the tabular iterations, can be specified in a constructor expression. These expressions then work in the same way as nested loops.
  • Unlike in a LET expression, a local field symbol cannot be declared instead of the iteration variable var.

The example creates a string from the numbers 0 to 9.

The example creates a string from the numbers 0 to 9.

Examples of Iteration Expressions






Vendor Master (General Section)   rdisp/max_wprun_time - Maximum work process run time  
This documentation is copyright by SAP AG.

Length: 7306 Date: 20240328 Time: 212749     sap01-206 ( 120 ms )