Ansicht
Dokumentation
ABENCDS_ARITHMETIC_EXPRESSION_V2 - CDS ARITHMETIC EXPRESSION V2
TXBHW - Original Tax Base Amount in Local Currency ABAP Short ReferenceThis documentation is copyright by SAP AG.
- CDS View Entity, arith_expr
... $[-$]operand1 $[+$|-$|*$|/ $[-$]operand2 $[+$|-$|*$|/ $[-$]operand3 ... $]$] ...
Effect
Arithmetic expression in a SELECT statement of a CDS view entity. An arithmetic expression uses arithmetic operators to calculate a numeric value from numeric operands. The possible operators are as follows:
Operator | Meaning |
+ | Adds the operands |
- | Subtracts the right operand from the left |
* | Multiplies the operands |
/ | Divides the left operand by the right |
A minus sign (-) before an operand multiplies the operand by -1. The data type of the operands must be numeric and be based on one of the built-in data types INT1, INT2, INT4, INT8, DEC, DECFLOAT16, DECFLOAT34, FLTP, or QUAN. The following can be specified:
- Numeric fields of a data source data_source of the current CDS view entity
- Parameter with numeric data type
- Path expressions that identify a numeric field of a data source data_source
- Built-in functions that return a numeric type
- Casting expressions that return a numeric type
- Case distinctions that return a numeric type
- Aggregate expressions that return a numeric type
- Another arithmetic expression
- A reuse expression using $projection
The subexpressions of an arithmetic expression can be placed in parentheses (...).
The following table shows which data types can be combined using the operators +, -, and * and the data type of the result:
+, -, * | INT1 | INT2 | INT4 | INT8 | DEC | DECFLOAT16 | DECFLOAT34 | FLTP | QUAN |
INT1 | INT4 | INT4 | INT4 | INT8 | DEC | DECFLOAT16 | DECFLOAT34 | - | QUAN |
INT2 | INT4 | INT4 | INT4 | INT8 | DEC | DECFLOAT16 | DECFLOAT34 | - | QUAN |
INT4 | INT4 | INT4 | INT4 | INT8 | DEC | DECFLOAT16 | DECFLOAT34 | - | QUAN |
INT8 | INT8 | INT8 | INT8 | INT8 | DEC | DECFLOAT16 | DECFLOAT34 | - | QUAN |
DEC | DEC | DEC | DEC | DEC | DEC | DECFLOAT16 | DECFLOAT34 | - | QUAN |
DECFLOAT16 | DECFLOAT16 | DECFLOAT16 | DECFLOAT16 | DECFLOAT16 | DECFLOAT16DECFLOAT16 | DECFLOAT16 | DECFLOAT34 | - | DECFLOAT16 |
DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | - | DECFLOAT34 |
FLTP | - | - | - | - | - | - | - | FLTP | - |
QUAN | QUAN | QUAN | QUAN | QUAN | QUAN | DECFLOAT16 | DECFLOAT34 | - | *: DECFLOAT34\lbr +, -: QUAN |
The following table shows which data types can be combined using the operator / and the data type of the result:
/ | INT1 | INT2 | INT4 | INT8 | DEC | DECFLOAT16 | DECFLOAT34 | FLTP | QUAN |
INT1 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | - | DECFLOAT34 |
INT2 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | - | DECFLOAT34 |
INT4 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | - | DECFLOAT34 |
INT8 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | - | DECFLOAT34 |
DEC | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | - | DECFLOAT34 |
DECFLOAT16 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT16 | DECFLOAT34 | - | DECFLOAT34 |
DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | - | DECFLOAT34 |
FLTP | - | - | - | - | - | - | - | FLTP | - |
QUAN | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | DECFLOAT34 | - | DECFLOAT34 |
It is also possible to use CDS amount fields and CDS quantity fields in arithmetic expressions. The result type can be a calculated quantity. The rules for amounts and quantities in arithmetic expressions in CDS view entities are explained in topic CDS View Entity, arith_exp, Amounts and Quantities.
Note the following special conditions:
- If an expression contains an operand of type DEC, the expression is a decimal expression. In this case, 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 an expression has an operand of type DECFLOAT16 or DECFLOAT34, then it is a decimal floating point expression.
- If an expression has an operand of type FLTP, then it is a binary floating point expression, in which all operands must be of type FLTP.
- When a division is performed with the operator /, the right operand cannot have the value 0.
- Data type CURR is also possible, but only under the following conditions:
- All operands must be of type CURR and have exactly two decimal places.
- CURR is only allowed in additions and subtractions (operators + and -). Not in multiplications and divisions.
Operand positions:
- Arithmetic expressions can be used as elements of a SELECT list, and there they need alternative element names defined using AS.
- An arithmetic expression can be used as the operand of an aggregate expression, a built-in function, a cast expression, or a case distinction.
- An arithmetic expression can be used in the condition cds_cond as operand lhs of a complex case distinction.
Notes
- To convert operands into the appropriate types, CAST expressions can be used. The built-in conversion function FLTP_TO_DEC can be used for the specific task of converting operands of type FLTP to packed numbers.
Example
SELECT list of a CDS view entity with arithmetic expressions.
BAL Application Log Documentation CPI1466 during Backup
This documentation is copyright by SAP AG.
Length: 18140 Date: 20240420 Time: 013508 sap01-206 ( 155 ms )