Ansicht
Dokumentation

ABENCDS_ARITHMETIC_EXPRESSION_V2 - CDS ARITHMETIC EXPRESSION V2

ABENCDS_ARITHMETIC_EXPRESSION_V2 - CDS ARITHMETIC EXPRESSION V2

TXBHW - Original Tax Base Amount in Local Currency   ABAP Short Reference  
This documentation is copyright by SAP AG.
SAP E-Book

- 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:

  • Another arithmetic expression

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.

Notes

  • When a division is performed with two numbers of type DEC, the SQL function DIVISION can be used.
  • 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 )