IT CanvassTalk to an advisor
SAP ABAP development · LessonReviewed by Anitha M, SAP Trainer, 13 yrs · Updated · Published · SAP S/4HANA 2023 · all levels

SAP 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.

Quick answer

ABAP conditions are IF with ELSEIF and ELSE, and CASE with WHEN and WHEN OTHERS, over comparisons combined with AND, OR and NOT plus predicates such as IS INITIAL, IS BOUND, BETWEEN and IN. Modern ABAP adds COND and SWITCH for inline values. Prefer CASE to nested IFs, use IS INITIAL rather than a literal, and handle WHEN OTHERS.

Key takeaways
  • 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.
Already working on SAP and stuck on a live ticket?Get an expert SAP developer on screen-share to finish your daily tasks with you. Deliver on time, protect your reputation and your job. Monthly support only, no task-wise plans.Task assigned · no idea where to startStill stuck · your job on the lineExpert joins your screenDelivered on timeExplore On Job Support