ABAP - Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP Database Accesses →  Open SQL →  Open SQL - Operands →  Open SQL - SQL Expressions → 

sql_exp - sql_arith

Syntax

... [-] operand1 +|-|*|/ [-]operand2 [+|-|*|/ [-] operand3 ... ] ...

Effect

Arithmetic expression in Open SQL. The operators perform arithmetic calculation between two adjacent operands. The possible operators are:

The operators * and / have a higher priority than the operators + and -. 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 +, -, *, or /.

The arithmetic expressions in Open SQL are distinguished as follows, depending on the data type of the operands:

Integer expressions use only integer operators, regardless of the parenthesis level. These operators have the dictionary type INT1, INT2, INT4, and INT8 or the ABAP type b, s, i, and int8 plus packed numbers of the types DEC, CURR, and QUAN or p without 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
Depending on the types of the operators, the result has the type INT4, INT8 or (if packed numbers are involved) is a packed number number with length 31 and no 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.
Alongside any integer operators (see above), decimal expression have at least one operator with the type DEC, CURR, or QUAN or p with 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.
If a decimal expression is specified statically, the syntax check checks that the result of each operation is in the value range of the type DEC with length 31 and a maximum of 14 decimal places. If any operands are specified that could produce other values, a syntax error occurs. If the expression is specified dynamically, an exception of the class CX_SY_DYNAMIC_OSQL_SEMANTICS is raised in this case.
Floating point expressions only have operators with the dictionary type FLTP or with the ABAP type f. Only 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 f in accordance with the associated assignment rule.

No other combinations of operand are allowed. The operands can be appropriate SQL expressions, which covers columns, literals, host variables, and host expressions.

If the operand of an arithmetic expression has the null value, the result of the full arithmetic expression is the null value.

Notes

Executable Example

SQL Expressions, Arithmetic Calculations