Conditions
Conditional logic, IF, CASE and logical expressions, lets ABAP make decisions. It is basic but the correctness of business logic hinges on getting conditions right.
Keep conditions readable, prefer clear structure and CASE over deeply nested IFs, and use IS INITIAL rather than comparing to literals.
- ABAP supports the usual comparisons (=, <>,, =) and combinations with AND, OR, NOT, plus useful predicates like IS INITIAL…
- It is basic but the correctness of business logic hinges on getting conditions right.
- Watch out: Deeply nested IFs that obscure logic; use CASE.
IF and CASE
IF lv_amount > 10000 AND lv_currency = 'USD'.
lv_approval = 'MANAGER'.
ELSEIF lv_amount > 1000.
lv_approval = 'TEAMLEAD'.
ELSE.
lv_approval = 'AUTO'.
ENDIF.
CASE lv_status.
WHEN 'O'. WRITE 'Open'.
WHEN 'C'. WRITE 'Closed'.
WHEN OTHERS. WRITE 'Unknown'.
ENDCASE.Logical expressions
ABAP supports the usual comparisons (=, <>, <, >, <=, >=) and combinations with AND, OR, NOT, plus useful predicates like IS INITIAL (empty/zero), IS BOUND (a reference is set), BETWEEN, and IN (for ranges/select-options). Modern ABAP adds COND and SWITCH expressions for inline conditional values.
Modern conditional expressions
DATA(lv_label) = COND string( WHEN lv_amt > 0 THEN 'Positive' ELSE 'Non-positive' ).
DATA(lv_txt) = SWITCH string( lv_status WHEN 'O' THEN 'Open' ELSE 'Other' ).Clarity over cleverness
Keep conditions readable, prefer clear structure and CASE over deeply nested IFs, and use IS INITIAL rather than comparing to literals. Readable conditions are less likely to hide business-logic bugs.
Common pitfalls
- Deeply nested IFs that obscure logic; use CASE.
- Comparing to '' or 0 instead of IS INITIAL.
- Missing WHEN OTHERS in CASE, unhandled values.