Skip to content

COMPUTE_INT_PLUS_OVERFLOW

An integer arithmetic result exceeded the maximum value for the target type.

The result of addition, subtraction, multiplication, or negation on a TYPE I or TYPE INT8 value went beyond the type's range.

Symptom

ST22 shows:

Runtime Errors         COMPUTE_INT_PLUS_OVERFLOW
Exception              CX_SY_ARITHMETIC_OVERFLOW
Short text             Overflow in integer arithmetic.

Cause

Type Range
TYPE I −2,147,483,648 to +2,147,483,647 (~2.1 billion)
TYPE INT8 −9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 (~9.2 × 10¹⁸)

Common triggers:

  • Multiplying two large TYPE I values (e.g. bytes × record count for total size).
  • Accumulating a count or sum that grows larger than ~2.1 billion.
  • Negating TYPE I minimum value (-2147483648 * -1 overflows).
  • Bit-shift operations on large values.

Reproduce

DATA: lv_a TYPE i VALUE 2000000000,
      lv_b TYPE i VALUE 2000000000,
      lv_result TYPE i.

lv_result = lv_a + lv_b.   " 4 billion > 2.1 billion max — dumps

Fix

DATA: lv_a      TYPE int8 VALUE 2000000000,
      lv_b      TYPE int8 VALUE 2000000000,
      lv_result TYPE int8.

lv_result = lv_a + lv_b.   " 4 billion — fits in INT8
DATA: lv_bytes   TYPE decfloat34,
      lv_records TYPE decfloat34,
      lv_total   TYPE decfloat34.

lv_bytes   = 1500.
lv_records = 5000000.
lv_total   = lv_bytes * lv_records.   " 7.5 billion — no overflow
TRY.
    lv_result = lv_a * lv_b.
  CATCH cx_sy_arithmetic_overflow INTO DATA(lx).
    MESSAGE lx->get_text( ) TYPE 'E'.
ENDTRY.

Use INT8 as the default for counters and sizes

TYPE INT8 costs no more performance than TYPE I on 64-bit systems and eliminates this class of overflow entirely for most practical values. Use it by default for any counter or accumulator that might exceed a few hundred million.

Prevention

  • Use TYPE INT8 instead of TYPE I for counters, sizes, and accumulators.
  • Use TYPE DECFLOAT34 for financial totals or any value with uncertain upper bounds.
  • When multiplying two TYPE I values, cast at least one to INT8 before the operation: DATA(lv_result) = CONV int8( lv_a ) * lv_b.

See also

Comments