SAP BUILTIN TYPES NUMERIC



Get Example source ABAP code based on a different SAP table
  


• b ABAP_TYPE
• decfloat16 ABAP_TYPE
• decfloat34 ABAP_TYPE
• f ABAP_TYPE
• i ABAP_TYPE
• int8 ABAP_TYPE
• p ABAP_TYPE
• s ABAP_TYPE

Built-In Numeric Types
The data objects of the numeric data types are used to store numeric values.

Properties TypeLengthStandard Length Meaning Data Object b1 byte Internal 1-byte integer type1 byte integer s2 byte Internal 2-byte integer type 2 byte integer i4 byte 4-byte integer type 4 byte integer int88 byte 8-byte integer type 8 byte integer p1 to 16 bytes8 byte Packed number typePacked number decfloat168 byte Decimal floating point number type with 16 places Decimal floating point number with 16 places decfloat3416 byte Decimal floating point number type with 34 places Decimal floating point number with 34 places f8 byte Binary floating point number type with 17 places Binary floating point number with 17 places

Value Ranges and Initial Values TypeValue RangeInitial Value b0 to 2550 s-32,768 to +32,7670 i-2,147,483,648 to +2,147,483,6470 int8-9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 0 pThe valid length for packed numbers is between 1 and 16 bytes. Two places are packed into one byte, where the last byte contains only one place and the sign, which is the number of places or places calculated from 2 * len1. After the decimal separator, up to 14 decimal places are allowed (the number of decimal places should not exceed the number of places). Depending on the field length len and the number of decimal places dec, the value range is: (-10^(2len-1) +1) / (10^(+dec)) to (+10^(2len-1) -1) /(10^(+dec)) in increments of 10^(-dec). Any intermediate values are rounded decimally. Invalid content produces undefined behavior.0 decfloat16Decimal floating point numbers of this type are represented internally with 16 places in accordance with the IEEE-754-2008 standard. Valid values are numbers between <(>1E385(1E-16 - 1)<)> and <(>-1E-383<)> for the negative range, 0 and <(>+1E-383<)> to <(>1E385(1 - 1E-16)<)> for the positive range. Values between the ranges form the subnormal range and are rounded. Outside of the subnormal range, each 16-digit decimal number can be represented exactly with a decimal floating point number of this type.0 decfloat34Decimal floating point numbers of this type are represented internally with 34 places in accordance with the IEEE-754-2008 standard. Valid values are numbers between <(>1E6145(1E-34 - 1)<)> and <(>-1E-6143<)> for the negative range, 0 to <(>+1E-6143<)> and <(>1E6145(1 - 1E-34)<)> for the positive range. Values between the ranges form the subnormal range and are rounded. Outside of the subnormal range, each 34-digit decimal number can be represented exactly using a decimal floating point number.0 fBinary floating point numbers are represented internally according to the IEEE-754 standard (double precision). In ABAP, 17 places are represented (one integer digit and 16 decimal places). Valid values are numbers between -1.7976931348623157E+308 and -2.2250738585072014E-308 for the negative range and between +2.2250738585072014E-308 and +1.7976931348623157E+308 for the positive range, plus 0. Both validity intervals are extended to the value zero by subnormal numbers according to IEEE-754. Not every 16-digit number can be represented exactly by a binary floating point number.0

ABAP_PGL
Selection of the numeric type
ABAP_PGL_END



Latest notes:

The numeric data objects are used to store numeric values and numeric calculations. Here, the data type f for binary floating point numbers is replaced largely by the types decfloat16 and decfloat34 for decimal floating point numbers.
The types b and s are internal and cannot be specified either statically or dynamically in ABAP statements. User-defined data types and data objects in ABAP programs have the data types b or s, provided that they were defined with reference to data elements of the ABAP Dictionary that have the external data types INT1 or INT2.
The system class CL_ABAP_MATH contains constants for the minimum and maximum values of most numeric types. The methods GET_MIN_VALUE and GET_MAX_VALUE in the class CL_ABAP_EXCEPTIONAL_VALUES can also be used.
The system class CL_ABAP_ELEMDESCR of RTTS contains constants TYPE_P_MAX_LENGTH and TYPE_P_MAX_DECIMALS for the maximum length and the maximum number of decimal places for the type p.
Due to the internal representation of the decimal places of a floating point number of type f as dual fractions, there is not an exact equivalent for every number that can be represented in the decimal system. This can cause rounding errors in assignments and interim results of calculations. These errors can be avoided by using a two-level rounding procedure (see Example ).
The type p, for which a length interval is specified in the second column of the first table, is generic, which means that the length is not part of the type description. In addition to the length, the number of decimal places is undefined. The entry in the column Standard Length determines the length that is used in declarations of data objects when using types with generic lengths, if no explicit length is specified in the corresponding statement.
The data type p is used to implement fixed point numbers. The number of decimal places in a packed number with the type p is a type property that is defined using the addition DECIMALS and that is not stored with the number. Technically, the numeric value is determined by dividing the stored string of digits of the packed number by 10 to the power of the number of decimal places (10^(+dec)). In the definition of a packed number, the number of decimal places should not be greater than the number of places calculated from 2 * len - 1. Otherwise, the decimal separator is outside the strings of digits and not all decimal places can be given values. For example, a packed number with length 1 and two decimal places would have a value range of -0.09 to +0.09 in increments of 0.01 but there cannot be a value for which the first decimal place is also filled, as for example 0.14.
A number with the data type p that has more decimal places than places can raise exceptions when converting to external formats such as data types of the database in AB_SQL or during serializations to asXML.
The built-in types of the ABAP Dictionary mapped to the data type p cannot have more decimal places than places. In ABAP, such declarations, if known statically, produce a syntax check warning.
See also Numeric Data Types.
For data objects with data type p, the program property Fixed Point Arithmetic must be set so that the decimal separator is respected. Otherwise, the content is handled in all operations as if there were no decimal separator. The sequence of digits in the variables of type p is interpreted as an integer value. Exceptions are:
Representation on screens
Assignments to character-like objects with the types c and string
NON_V5_HINTS
Formatting with WRITE $[TO$]
ABAP_HINT_END

ABAP_EXAMPLE_VX5
Declaration of variables with built-in numeric ABAP types for a numeric calculation.
ABEXA 00841
ABAP_EXAMPLE_END

ABAP_EXAMPLE_ABEXA
Value Ranges of Packed Numbers
ABAP_EXAMPLE_END