In SAP ABAP, integer and numeric data types are used for numerical calculations but have key differences in terms of storage, precision, and usage.
🔢 1. Integer (I
, INT1
, INT2
, INT4
)
- Used for whole numbers (no decimal points).
- Takes fixed memory size (1, 2, or 4 bytes).
- Fast processing for counting, indexing, or simple arithmetic.
- If you divide an integer, the result will be converted to a decimal unless
DIV
is used.
Example (Integer Calculation)
DATA: lv_int1 TYPE I VALUE 10, lv_int2 TYPE I VALUE 3, lv_result TYPE I.
lv_result = lv_int1 / lv_int2. " Normal divisionWRITE: lv_result. " Output: 3 (Decimal part is removed due to integer storage)
lv_result = lv_int1 DIV lv_int2. " Integer divisionWRITE: lv_result. " Output: 3
📌 Key Integer Data Types:
Type | Description | Value Range |
---|---|---|
I | Integer (4 bytes) | -2,147,483,648 to +2,147,483,647 |
INT1 | Tiny Integer (1 byte) | 0 to 255 |
INT2 | Small Integer (2 bytes) | -32,768 to +32,767 |
INT4 | Standard Integer (4 bytes, same as I ) | Same as I |
🔢 2. Numeric (P
, F
, DEC
)
- Used for both whole and decimal numbers (floating point and fixed precision).
- Takes variable memory size depending on the declaration.
- Used for precise calculations like financial data, currency, and measurements.
- Division results remain accurate with decimals.
Example (Numeric Calculation)
DATA: lv_num1 TYPE P DECIMALS 2 VALUE 10, lv_num2 TYPE P DECIMALS 2 VALUE 3, lv_result TYPE P DECIMALS 2.
lv_result = lv_num1 / lv_num2.WRITE: lv_result. " Output: 3.33 (Decimals retained)
📌 Key Numeric Data Types:
Type | Description | Value Range & Precision |
---|---|---|
P | Packed Decimal (BCD) | Up to 31 digits with decimals |
F | Floating Point (8 bytes) | Large range with rounding errors |
DEC | Decimal Number | Similar to P , mainly in DDIC |
🔄 Key Differences: Integer vs. Numeric
Feature | Integer (I , INT* ) | Numeric (P , F , DEC ) |
---|---|---|
Stores | Whole numbers only | Whole + decimal numbers |
Memory | Fixed (1, 2, or 4 bytes) | Variable (depends on precision) |
Precision | No decimal support | Supports decimals |
Usage | Counting, indexing, loop counters | Financial, currency, measurements |
Division | Results in integer unless using float | Retains decimal values |
🚀 When to Use What?
✅ Use Integer (I
, INT*
) when you need:
- Loop counters (
DO
,WHILE
). - Counting values (e.g., number of items).
- Simple arithmetic operations.
✅ Use Numeric (P
, F
) when you need:
- Financial calculations (e.g., price, salary).
- Precise decimal values (e.g., 12.3456).
- Large number calculations (e.g., scientific data).
Would you like an example of working with both in the same program? 😊