Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Program Flow →  Control Structures →  Branches 

IF

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


IF log_exp1. 
  [statement_block1]
[ELSEIF log_exp2.
  [statement_block2]]
...
[ELSE.
  [statement_blockn]]
ENDIF.

Effect

These statements define a control structure which can contain multiple statement blocks statement_block of which a maximum of one will be executed in conjunction with logical expressions log_exp.

After IF and ELSEIF any logical expressions log_exp can be executed while the expressions statement_block stand for any statement blocks.

The logical expressions, beginning with the IFstatement, are checked from top to bottom and the statement block after the first is executed during the logical expression. If none of the logical expressions are true, the statement block after the ELSE statement is executed.

When the end of the statement block is reached or if no statement block is to be executed, the processing is continued after ENDIF.


Example

Converting a time output into the 12-hour format (see also country-specific formats).

DATA time TYPE t. 

fltime = sy-time. 

IF time < '120000'. 
  WRITE: / time, 'AM' . 
ELSEIF time > '120000' AND 
       time < '240000'. 
  time = time - 12 * 3600. 
  WRITE: / time, 'PM' . 
ELSE. 
  WRITE / 'High Noon'. 
ENDIF. 

Continue

ELSEIF

ELSE

ENDIF