SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
ABAP Keyword Documentation → ABAP − Reference → Predefined Types, Data Objects, Functions, and Constructors → Predefined Data Types → Predefined ABAP Types →Predefined Numeric Types
The data objects of the numeric data types are used to handle number values.
Properties
Type | Length | Standard Length | Name |
b | 1 byte | 1-byte integer (internal) | |
s | 2 byte | 2-byte integer (internal) | |
i | 4 byte | 4-byte integer | |
p | 1 to 16 bytes | 8 byte | Packed number |
decfloat16 | 8 byte | Decimal floating point number with 16 decimal places | |
decfloat34 | 16 byte | Decimal floating point number with 34 decimal places | |
f | 8 byte | Binary floating point number with 17 decimal places |
Value Ranges and Initial Values
Type | Value Range | Initial Value |
b | 0 to 255 | 0 |
s | -32,768 to +32,767 | 0 |
i | -2,147,483,648 to +2,147,483,647 | 0 |
p | The valid length for packed numbers is between 1 and 16 bytes; two decimal places are packed into one byte, whereby the last byte only contains one place and the plus/minus sign; after the decimal separator, up to 14 decimal places are permitted. Depending on the field length len and the number of decimal places dec, the following applies for the value range: (-10^(2len -1) +1) / (10^(+dec)) to (+10^(2len -1) -1) /(10^(+dec)) in steps of 10^(-dec). Values in between this range are rounded; invalid contents result in undefined behavior. | 0 |
decfloat16 | Decimal floating point numbers of this type are represented internally with 16 decimal 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 lying between the ranges form the subnormal range and are rounded; outside of the subnormal range, each 16-digit decimal number can be represented precisely with such a decimal floating point number | 0 |
decfloat34 | Decimal floating point numbers of this type are represented internally with 34 decimal 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 and +1E-6143 and 1E6145(1 - 1E-34) for the positive range. Values lying between the ranges form the subnormal range and are rounded; outside of the subnormal range, each 34-digit decimal number can be represented precisely with such a decimal floating point number | 0 |
f | Binary floating point numbers are represented internally in accordance with the IEEE-754 standard (double precision); in ABAP, 17 decimal places are represented (one place before the decimal point and 16 places in the fractional part). 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 in the direction of zero using subnormal numbers in accordance with the IEEE-754 standard. | 0 |
Programming Guideline
Notes
Example
According to the formula in the table, the value range of a packed number with length 2 and two decimal places is (-10^(2x2 -1) +1) / (10^2) to (+10^(2x2 -1) -1) / (10^2) and therefore =-9.99 to +9.99 in steps of 0.01. A value within this range, for example 1.428, is rounded up to 1.43.
DATA: pack TYPE p LENGTH 2 DECIMALS 2,
result TYPE REF TO data.
FIELD-SYMBOLS <result> TYPE ANY.
result = cl_abap_exceptional_values=>get_min_value( pack ).
IF result IS NOT INITIAL.
ASSIGN result->* TO <result>.
cl_demo_output=>write_data( <result> ).
ENDIF.
result = cl_abap_exceptional_values=>get_max_value( pack ).
IF result IS NOT INITIAL.
ASSIGN result->* TO <result>.
cl_demo_output=>write_data( <result> ).
ENDIF.
cl_demo_output=>display( ).