Operators & Expressions
Classic statements ADD, SUBTRACT, MULTIPLY, DIVIDE and COMPUTE still exist but are obsolete.
7.1 Arithmetic
a = b * c / d. Remainder (always ≥ 0) Calculation assignments (7.54+) lv_sum += lv_amount.
Classic statements ADD, SUBTRACT, MULTIPLY, DIVIDE and COMPUTE still exist but are obsolete. Result types follow the calculation type (the "largest" type among operands); integer division with / rounds commercially.
Numeric functions: abs( ), sign( ), ceil( ), floor( ), trunc( ), frac( ), round( val = x dec = 2 ), ipow( base = 2 exp = 8 ), nmin( ), nmax( ), sqrt( ), exp( ), log( ), log10( ), sin( ) etc.
7.2 Comparison operators
less / greater less-equal / greater-equal BETWEEN a AND b has initial value reference points to an object field symbol assigned optional parameter was passed matches a ranges table / select-option IS INSTANCE OF object type check
String comparisons: CO (contains only), CN (not CO), CA (contains any), NA, CS (contains string, case-insensitive), NS, CP (covers pattern with * and +), NP. They set sy-fdpos.
7.3 Boolean logic
ABAP has no real boolean type: use abap_bool (c LENGTH 1) with constants abap_true ('X') and abap_false (' '). Turn a condition into a value with xsdbool( ):
IF lv_amount > 1000 AND ( lv_status = 'O' OR lv_status = 'P' ) AND NOT lv_blocked = abap_true.
ENDIF.DATA(lv_is_big) = xsdbool( lv_amount > 1000 ).7.4 Constructor and conditional operators (7.40+)
Create object / data NEW zcl_x() Structures / internal tables VALUE #( a = 1 b = 2) CONV string( 42) CAST zcl_sub( lo_super) REF #( lv_x) EXACT i( lv_c) Map by component name CORRESPONDING #( ls_src) If/else as expression Case as expression Aggregate over iterations Filter internal table by key
DATA(lv_grade) = COND string(
WHEN lv_score >= 90 THEN `A`
WHEN lv_score >= 75 THEN `B`
WHEN lv_score >= 50 THEN `C`
ELSE `F` ).
DATA(lv_day_name) = SWITCH string( lv_weekday
WHEN 1 THEN `Monday`
WHEN 2 THEN `Tuesday`
ELSE THROW zcx_invalid_day( ) ).7.5 Bit operators
BIT-AND, BIT-OR, BIT-XOR, BIT-NOT on x/xstring operands; SET BIT / GET BIT statements.