Inline Declaration With Packed Arithmetic Loses Decimals
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_PACKEDRelated Rules
- Prefer Calculation Assignment Operators (+=, -=, *=, /=) —
#EC PREF_CALC_OP - Prefer Inline Declarations over Separate DATA and Assignment —
#EC PREF_INLINE
Technical Details
- Native ATC Class:
/SKYL/CL_NO_INLINE_PACKED - ABAP Implementation: /skyl/cl_no_inline_packed.clas.abap
- Rule Metadata: rules-data.mjs (Line 6039)