Show TOC

Program Flow LogicLocate this document in the navigation structure

Concept

Conditional Branches

In a conditional branch with IF, precisely one statement block statement_block is executed (dependent on logical expressions log_exp):

               IF log_exp.
  statement_block
ELSEIF log_exp.
  statement_block
ELSEIF ...
    ...

ELSE.
  statement_block

ENDIF.
            

In a condition branch with CASE, a data object dobj is compared in sequence with a range of other data objects dobj1 . . . dobjn. After the first match, the associated statement block statement_block is executed and the CASE structure is then exited. This means that only one statement block is executed at most. Specifying a standard statement block in the final position of the condition WHEN OTHERS (executed if the preceding comparisons did not produce any matches), guarantees that precisely one statement block is always executed.

               CASE dobj.
  WHEN dobj1 OR dobj2 ...
    statement_block
  WHEN ...
      ...
  WHEN OTHERS.
  statement_block
ENDCASE.
            

Loops

In an unconditional loop, a statement block statement_block is enclosed between the statements DO and ENDDO. The optional addition TIMES can also be used to specify how often the statement block is executed.

               DO n TIMES.
  statement_block
ENDDO.
            

In a conditional loop with WHILE, a statement block statement_block is executed until the logical expression log_exp is true.

               WHILE log_exp.
  statement_block
ENDWHILE.
            

Within a loop, the system field sy-index contains the number of previous passes (including the current pass). In nested loops, sy-index always refers to the current loop. The statement CONTINUE can be used to exit the current loop pass prematurely. The program flow logic then continues with the next pass. The statement CHECK log_exp is a conditional variant of CONTINUE. The loop pass is exited if the result of the logical expression log_exp is not true. The statement EXIT is used to exit a loop completely. In this case, the program flow logic continues with the statement following the loop statement that just closed.