Professional Documents
Culture Documents
saphub.com/abap-tutorial/control-statements
To control the flow of the ABAP program use the following statements.
IF – Branching Conditionally
IF statement – The code between IF and ENDIF is executed only if the condition is true.
DATA: a TYPE i VALUE 10. " We can assign a value in the declaration
IF a > 5.
WRITE:/ 'Condition True'.
ENDIF.
Output
IF a > 5.
WRITE:/ 'Condition True'.
ELSE.
WRITE:/ 'Condition False'.
ENDIF.
Output
IF a > 5.
WRITE:/ a, 'Greater Than', 5.
ELSEIF a > 4.
WRITE:/ a, 'Greater Than', 4.
ELSEIF a > 3.
WRITE:/ a, 'Greater Than', 3.
ELSE.
WRITE:/ a, 'Less Than', 3.
ENDIF.
Output
1/2
DATA: a TYPE i VALUE 4.
CASE a.
WHEN 3.
WRITE:/ a, 'Equals', 3.
WHEN 4.
WRITE:/ a, 'Equals', 4.
WHEN OTHERS.
WRITE:/ 'Not Found'.
ENDCASE.
Output
2/2