sql_exp - sql_arith
7.31 | 7.40 | 7.54
... [-] sql_exp1 +|-||/ [-] sql_exp2 [+|-||/ [-] sql_exp3 ... ] ...
Arithmetic expression in ABAP SQL. The operators perform arithmetic calculations between two adjacent
sql_exp2, and so on. The possible operators are:
+for adding the operands
-for subtracting the right operand from the left operand
*for multiplying the operands
/for dividing the left operand by the right operand
/ have a higher priority than the operators
-. Within a
parenthesis level, operations with a higher priority
are performed before those with a lower priority. Operations with identical priorities are performed
from left to right. A minus sign
- can be placed in front of an operand that
does not directly follow an operator
The arithmetic expressions in ABAP SQL are distinguished as follows, depending on the data type of the operands:
- Integer Expressions
int8plus packed numbers of the types DEC, CURR, and QUAN or
pwithout decimal places. The operator / is not allowed in integer expressions. An overflow occurs and an exception of the class CX_SY_OPEN_SQL_DB is raised when
- the value range of the type INT4 or
iis exceeded in operations between two integer numbers where neither of the numbers has the type INT8,
- the value range of the type INT8 or
int8is exceeded in operations between two integer numbers where one of the numbers has the type INT8,
- the value range of a packed number with length 31 without decimal places is exceeded in operations using packed numbers.
- Decimal Expressions
pwith decimal places. The operator
/is not allowed in decimal expressions. The result has the type DEC with the length 31 and a maximum of 14 decimal places. Using the associated assignment rule, it can be assigned to all numeric ABAP types whose value range is large enough, except for decimal floating point numbers.
- Decimal Floating Point Expressions
p, decimal floating point expressions have at least one operand of the type DECFLOAT16 or DECFLOAT34 or of the ABAP type
decfloat34Decimal floating point expressions permit division between two decimal floating point numbers of types DECFLOAT16 or DECFLOAT34 using the operator
/. Depending on the types of the operands, the result has the type DECFLOAT16 or DECFLOAT34. Using the associated assignment rule, it can be assigned to the ABAP types
decfloat34. If an operation exceeds the value range of the result type or division by 0 takes place, an overflow occurs and an exception of the class CX_SY_OPEN_SQL_DB is raised.
- Binary Floating Point Expressions
f. Only binary floating point expressions permit division with the operator
/. If an operation exceeds the value range of the type FLTP or division by 0 takes place, an overflow occurs and an exception of the class CX_SY_OPEN_SQL_DB is raised. The result has the type FLTP and can only be assigned to a field with the ABAP type
fin accordance with the associated assignment rule.
No other combinations of operand are allowed. The operands can all be SQL expressions of the specified data types.
If the operand of an arithmetic expression has the null value, the result of the full arithmetic expression is the null value.
- Specifying an arithmetic expression always means specifying an SQL expression. Arithmetic expressions can only be specified for operand positions for which SQL expressions are possible.
- The arithmetic expressions have been divided into the three categories integer expressions, decimal expressions, and floating point expressions to achieve the same behavior in all supported database systems.
- Operators that do not have the type FLTP can be transformed to an operator with the type FLTP using
CASTexpression and hence used in binary floating point expressions.
- Decimal floating point numbers are not supported in SQL expressions and are not valid data types of the operands here.
- A plus sign
+cannot be specified in front of an operand of an arithmetic expression. If a minus sign
-is specified after an operator
/, the sign and the operand must be placed in parentheses.
- If an operand is prefixed with a minus sign (
-), the syntax check is performed in a strict mode, which handles the statement more strictly than the regular syntax check.
Arithmetic expression as an argument of the built-in function
DIVISION in a
list. To be able to use the operator
/ instead of
DIVISION, its operands would have to be
cast to DECFLOAT16, DECFLOAT34, or FLTP and the result would also have the corresponding type.
SELECT FROM sflight FIELDS fldate, DIVISION( ( seatsmax - seatsocc ) * 100, seatsmax, 2 ) AS availability WHERE carrid = 'LH' AND connid = 400 ORDER BY fldate INTO TABLE @DATA(result).