Skip to content

COMPUTE_INT_ZERODIVIDE

An integer division by zero was attempted.

ABAP integer arithmetic (TYPE I, INT8) does not produce infinity or NaN — dividing by zero immediately dumps the program.

Symptom

ST22 shows:

Runtime Errors         COMPUTE_INT_ZERODIVIDE
Exception              CX_SY_ZERODIVIDE
Short text             Division by zero (integer arithmetic).

The dump line is the / or DIV or MOD operation where the divisor is zero.

Cause

Any division where the divisor evaluates to zero at runtime:

  • A loop counter or aggregate that legitimately reaches zero (e.g. empty result set).
  • A user-supplied denominator that was not validated.
  • A calculated field that becomes zero in edge cases.
  • MOD and DIV (integer division) behave the same as / — all three dump on zero.

Floating point behaves differently

TYPE F (float) division by zero does not dump — it produces +Infinity. Only integer (TYPE I, INT8) and packed (TYPE P) division dumps with this error. Packed division dumps as BCD_OVERFLOW, not COMPUTE_INT_ZERODIVIDE.

Reproduce

DATA: lv_total TYPE i VALUE 100,
      lv_count TYPE i VALUE 0,
      lv_avg   TYPE i.

lv_avg = lv_total / lv_count.   " <-- dumps

Fix

DATA: lv_total TYPE i VALUE 100,
      lv_count TYPE i VALUE 0,
      lv_avg   TYPE i.

IF lv_count > 0.
  lv_avg = lv_total / lv_count.
ELSE.
  lv_avg = 0.   " or handle as appropriate
ENDIF.
TRY.
    lv_avg = lv_total / lv_count.
  CATCH cx_sy_zerodivide INTO DATA(lx).
    lv_avg = 0.
    " optionally log: MESSAGE lx->get_text( ) TYPE 'I'.
ENDTRY.
DATA(lv_avg) = COND i(
  WHEN lv_count > 0 THEN lv_total / lv_count
  ELSE 0 ).

Prevention

  • Treat every division as a potential zero-divide: add an IF divisor > 0 check or COND before each /, DIV, or MOD.
  • When the divisor comes from a database aggregate (COUNT(*), SUM), always test for the empty-result case.
  • Add a unit test with a zero denominator for any method that performs division.

See also

Comments