CASE

Short Reference

Syntax

CASE operand.
  [WHEN operand1 [OR operand2 [OR operand3 [...]]].
    [statement_block1]]
  ...
  [WHEN OTHERS.
    [statement_blockn]]
ENDCASE.

Effect

These statements define a control structure that can contain multiple statement blocks statement_block1, ..., statement_blockn, of which no more than one is executed depending of the value in the operand operand.

Starting with the first WHEN statement, the content of the operand in operand is compared with the content of one of the operands operand1, operand2, ... from the top down. The statement block is executed after the first identical instance is found. If no matches are found, the statement block is executed after the statement WHEN OTHERS.

For operand, operand1, operand2, and so on, you can use data objects, predefined functions (as of release 6.10) and functional methods. With the latter, you receive the return value as an operand.

If the end of the executed statement block is reached or no statement block is executed, processing continues after ENDCASE.

For the comparison of the contents, the following logical expression can be used:

operand = operand1 [OR operand = operand2
                   [OR operand = operand3 [...]]]

For the comparison depending on the data types of the operands involved, the same rules therefore apply as described in the section Relational Operators for all Data Types.

Notes

Example

Branching the program flow depending on the function code in system field sy-ucomm.

CASE sy-ucomm.
  WHEN 'BACK'.
    LEAVE TO SCREEN 100.
  WHEN 'CANCEL'.
    LEAVE SCREEN.
  WHEN 'EXIT'.
    LEAVE PROGRAM.
  WHEN OTHERS.
    MESSAGE '...' TYPE 'E'.
ENDCASE.