ABAP Keyword Documentation → ABAP − Reference → Declarations → Declaration Statements → Data Types and Data Objects → Declaring Data Objects → Literals
Numeric Literals
Other versions:
7.31 | 7.40 | 7.54
Syntax
... [+|-]n[n[n[...]]] ...
Effect
A number literal consists of a continuous sequence of numbers with a maximum of 31 digits n
(0
to 9
), which can be directly preceded by a plus (+
) or minus (-
) sign.
- Numeric literals between -2147483648 and 2147483647 are
integer literals and
have the built-in ABAP type
i
.
- Numeric literals outside of this interval are
packed numeric literals
and have the built-in ABAP type
p
, with a length of 8 bytes if they are not longer than 15 digits and with a length of 16 bytes if they are between 16 and 31 digits long.
Notes
- There are no numeric literals of type
int8
. The conversion operatorCONV
can be used to convert a numeric literal to the typeint8
.
- Packed numeric literals have a different representation from integer literals. They cannot be cast directly on field symbols with the data type integer.
- In numeric literals, it is not possible to use either decimal separators or scientific notation with mantissa and exponent.
- Numbers that cannot be represented as numeric literals can only be specified in character literals. If used in operand positions in which a numeric value is expected, they are converted accordingly. The
conversion operator
CONV
is recommended for targeted conversions.
- Numeric literals that span multiple lines are not permitted. Furthermore, the
literal operator
&
cannot be used to create a composite literal from multiple numeric literals.
- A numeric literal
+|-literal
directly prefixed with a plus or minus sign is not to be confused with a simple arithmetic expression+|- literal
for which there is a space between the operator+|-
and an unsigned literal. In contrast with the numeric literal, the expression is not evaluated until runtime. Therefore, in such cases the numeric literal is always to be used, for performance reasons.
Example
The first literal is of the type i
. The following literals are of the type p
with lengths 8 and 16.
DATA: t TYPE c LENGTH 1,
l TYPE i.
DESCRIBE FIELD
123456
TYPE t.
cl_demo_output=>write( t ).
DESCRIBE FIELD
123456790123
TYPE t
LENGTH l
IN BYTE MODE.
cl_demo_output=>write( |{ t } { l }| ).
DESCRIBE FIELD
12345679012345678
TYPE t
LENGTH l
IN BYTE MODE.
cl_demo_output=>write( |{ t } { l }| ).
cl_demo_output=>display( ).
Example
Targeted conversion of a character literal into type int8
.
DATA(num) = CONV int8( '123456790123' ).
Example
The example shows that a casting of a
packed numeric literal to the type int8
has a different result than when
using a field of the type int8
, due to the different internal representation. If the field symbol <fs2>
were typed with the
time stamp type
utclong
, an exception would even be raised for the use in the embedded expression of the output.
FIELD-SYMBOLS <fs1> TYPE int8.
FIELD-SYMBOLS <fs2> TYPE int8.
DATA num TYPE int8.
num = 3155380704000000000.
ASSIGN num TO <fs1> CASTING.
ASSIGN 3155380704000000000 TO <fs2> CASTING.
cl_demo_output=>display( |{ <fs1> } \n| &&
|{ <fs2> }| ).