11.6Bloom · AnNot started

Numeric-type pitfalls

Reading depth

What you'll learn

Use DECFLOAT for money (binary float drifts), always give packed P explicit DECIMALS, reach for INT8 past 2^31, and prefer a single UTCLONG over a date+time pair.

  • DECFLOAT16 / DECFLOAT34 are the safe types for financial math — binary FLTP drifts and fails reconciliation.
  • Packed P needs explicit DECIMALS, or the scale is silently wrong.
  • INT8 (8-byte) is required for counters that can exceed 2^31; INT4 overflows.

Financial math has a hard rule: use DECFLOAT16 or DECFLOAT34, never binary floating point. Binary FLTP cannot represent most decimal fractions exactly, so sums of money drift by fractions of a cent and fail reconciliation. The decimal floating-point types carry 16 and 34 significant digits respectively with exact decimal behaviour, which is why they are the safe choice for amounts and rates.

The packed type P is the historical default for amounts, and its trap is the DECIMALS specification: declare a packed field without explicit DECIMALS and you inherit whatever default applies, which silently truncates or misplaces the decimal point. Always state DECIMALS so the scale is unambiguous. For counters, the trap is range — a four-byte integer overflows at 2^31, so anything that can exceed roughly two billion (document numbers, event counters) needs INT8, the eight-byte integer.

For timestamps in new tables, prefer UTCLONG. It is a single eight-byte high-precision UTC timestamp, which is simpler and less error-prone than the legacy pattern of a separate date field and time field that you must keep consistent and time-zone-correct yourself. One UTCLONG column replaces the (date, time) pair and removes a whole class of off-by-one and time-zone bugs.

Key points

  • DECFLOAT16 / DECFLOAT34 are the safe types for financial math — binary FLTP drifts and fails reconciliation.
  • Packed P needs explicit DECIMALS, or the scale is silently wrong.
  • INT8 (8-byte) is required for counters that can exceed 2^31; INT4 overflows.
  • UTCLONG — one high-precision UTC timestamp — is preferred over a (date, time) pair for new tables.

Examples

AfterDECFLOAT for money, UTCLONG for time

Decimal floating point keeps amounts exact; a single UTCLONG replaces a separate date and time pair.

ABAPdata lv_amount type decfloat34.
data lv_stamp  type utclong.

Source notes: clean-core-curriculum §11.6

Ask Claude

Build a prompt from this lesson + your question and open a fresh Claude chat with it pre-filled — handy for adapting a before/after pattern to your own object.