SAP NUMBERS - Guide
Get Example source ABAP code based on a different SAP table
GUIDELINE 6.15
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:
A sequence of digits with a maximum of one period (.) as a decimal separator and an optional sign '+' or '-' on the left. This sign can be separated from the digits by blanks, for example: - 1234.56
A sequence of digits with a maximum of one period (.) as a decimal separator and an optional sign '+' or '-' on the right. This sign can be separated from the digits by blanks, for example: 1234.56-
A sequence consisting of a mantissa (an optional sign '+' or '-', digits with a maximum of one period (.) as a decimal separator), a character
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 digits. This notation also confirms to other standards, such as the canonic representation of
Bad example
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.
Good example
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.