Skip to content

Inline Declaration With Packed Arithmetic Loses Decimals ​

WarningAnti-Patterns & Bad Practices#EC NO_INLINE_PACKEDRemote Enabled✏️ Edit Rule on GitHub

Overview ​

Inline declaration with packed arithmetic loses decimals.

ATC Finding Message: DATA(...) with packed arithmetic defaults to P(8,0) and loses decimals

Rationale ​

When an arithmetic expression involving packed numbers (TYPE p) is assigned to an inline declaration DATA(...), ABAP derives the target variable type as P LENGTH 8 DECIMALS 0. As a consequence, all decimal places are silently truncated, resulting in loss of precision in financial and mathematical computations. Use an explicit DATA declaration with DECIMALS or CONV #( ... ).

Non-Compliant ​

abap
DATA lv_price TYPE p DECIMALS 2 VALUE '12.50'.
DATA(lv_total) = lv_price * 10 / 3.

Compliant ​

abap
DATA lv_price TYPE p DECIMALS 2 VALUE '12.50'.
DATA lv_total TYPE p DECIMALS 2.
lv_total = lv_price * 10 / 3.

Suppression ​

To suppress findings for this rule, append the pseudo-comment to the statement:

abap
" Standard pseudo-comment:
... "#EC NO_INLINE_PACKED

" SAP CI_ prefix format:
... "#EC CI_NO_INLINE_PACKED

Technical Details ​

Community & Feedback ​

Released under the MIT License.