SAP NUMBERS - Guide
Get Example source ABAP code based on a different SAP table
Specifying Numbers
ABAP_BACKGROUND
There are no special literals available for numbers with decimal places, or with mantissa plus exponent. If required, these numbers must be expressed using character literals. The following notations can be used:
ABAP_RULE
When using numbers in character strings that are intended for assignments to a numeric data object, create them so that they are acc epted by all possible target types. The sign must always be on the left, and there must be no blanks.
ABAP_DETAILS
When converting a character string to a numeric variable, the type of the target variables decides which notations are accepted:
To make sure that a program is readable, and also that numbers in character strings can be converted to as many numeric data types as possible, always use mathematical notation without blanks between the sign and the string of digits. This notation also confirms to other standards, such as the canonic representation of XML schema data types.
ABAP_EXAMPLE_BAD
The following source code demonstrates the initialization of a generically typed parameter with commercial notation, where the sign is separated by a blank. If an actual parameter with a type other than f is passed, the assignment produces the value -1000 (as expected); if an actual parameter of the type
PUBLIC SECTION.
METHODS calculate_something
EXPORTING number TYPE numeric.
ENDCLASS.
CLASS class IMPLEMENTATION.
METHOD calculate_something.
number = '1000 -'.
...
ENDMETHOD.
ENDCLASS.>
ABAP_EXAMPLE_END
ABAP_EXAMPLE_GOOD
The following source code demonstrates an assignment using globally valid notation that is easy to read and which produces the same result, the value -1000, for all numeric data types.
number = '-1000'.
...
ENDMETHOD.>
ABAP_EXAMPLE_END