SAP ABAP — Control Statement
Case Control Statement
The CASE control statement is used when we need to compare two or more fields.
No logical expressions can be used for the <field> field.
The field strings used in the CASE statement are treated as type C variable.
CASE VARIABLE.
WHEN VALUE1.
………
WHEN VALUE2.
………
WHEN OTHERS.
………
ENDCASE.
DO.
Example :
REPORT Z_ABAP_DEVELOPER_TEST.
DATA: A TYPE I VALUE 5.
CASE A.
WHEN 3.
WRITE:/ A, ‘Equals’, 3.
WHEN 4.
WRITE:/ A, ‘Equals’, 4.
WHEN 5.
WRITE:/ A, ‘Equals’, 5.
WHEN OTHERS.
WRITE:/ ‘Not Found’.
ENDCASE.
Output :
IF Control Statement
IF-ELSE statement — The code between IF and ELSE is executed if the condition is true, the code between ELSE and ENDIF is executed if the condition is False.
IF [NOT] EXP [ AND / OR [NOT] EXP ].
……..
[ELSEIF EXP.
…….]
[ELSE.
…….]
ENDIF.
Example :
REPORT Z_ABAP_DEVELOPER_TEST.
DATA: A TYPE I VALUE 2.
IF A > 4.
WRITE:/ ‘Condition True’.
ELSE.
WRITE:/ ‘Condition False’.
ENDIF.
DATA : B TYPE I VALUE 8.
IF B > 6.
WRITE:/ ‘Condition True’.
ELSE.
WRITE:/ ‘Condition False’.
ENDIF.
Output :