Ansicht
Dokumentation

ABENCDS_ARIT_EXP_CALC_V2 - CDS ARIT EXP CALC V2

ABENCDS_ARIT_EXP_CALC_V2 - CDS ARIT EXP CALC V2

General Material Data   General Data in Customer Master  
This documentation is copyright by SAP AG.
SAP E-Book

- CDS View Entity arith_expr, Amounts and Quantities

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

Effect

Arithmetic expression in a SELECT statement of a CDS view entity that operates with CDS amount fields, CDS quantity fields, and calculated quantities. 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 operands must be CDS amount fields, CDS quantity fields, CDS calculated quantities, or numeric values of one of the following data types: INT1, INT2, INT4, INT8, DEC, DECFLOAT16, DECFLOAT34, FLTP, or QUAN. The operands can be specified as follows:

  • CDS amount fields and CDS quantity fields must be fields of a data source data_source of the current CDS view entity.

The subexpressions of an arithmetic expression can be placed in parentheses (...).

The following table shows how amount fields and quantity fields can be used with different operators and the type of the result:

operands / operators / * +, -
amount, amount calculated quantity calculated quantity amount
quantity, quantity calculated quantity calculated quantity quantity
calculated quantity, amount calculated quantity calculated quantity amount
amount, quantity calculated quantity calculated quantity -
calculated quantity, number calculated quantity calculated quantity -
calculated quantity, quantity calculated quantity calculated quantity quantity
calculated quantity, calculated quantity calculated quantity \lbr calculated quantity calculated quantity
amount, number amount amount -
number, amount calculated quantity amount -
quantity, number quantity quantity -
number, quantity calculated quantity quantity -

Regarding the data types of the operands and of the result, the rules for arithmetic expressions apply, see topic CDS View entity arith_expr. If the result is a calculated quantity, then the data type is always DECFLOAT34.

Note the following special conditions:

  • If the result of an arithmetic expression is a CDS amount field, CDS quantity field, or a calculated quantity, then it is mandatory to assign a currency key, unit key, or calculated unit using the respective Semantics annotation. If no reference is assigned, a syntax check error occurs. References are not inherited or derived from the operands of the arithmetic expression.
  • The following rules apply to CDS amount fields of data type CURR:
  • In general, CDS amount fields of data type CURR can't be used directly as operands of arithmetic expressions. They need to be converted to data type DECFLOAT34 first, using the conversion function CURR_TO_DECFLOAT_AMOUNT.

There's only one exception to this rule: if all operands are of data type CURR and have exactly two decimal places, then they can be used in additions and subtractions (operators + and -).
  • A calculated quantity can be changed back to an amount or quantity field using the function GET_NUMERIC_VALUE. Then, the required reference can be added using the required annotation, Semantics.amount.currencyCode or Semantics.quantity.unitofMeasure.
  • If one of the operands is 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.

Notes

  • A calculated unit can be used as reference only once in a view. If a view contains several calculated quantity fields, each field needs a different calculated unit.

Example

SELECT list of a CDS view entity with amounts and quantities in arithmetic expressions:

  • For the calculation of the field my_calcQuan, the currency field needs to be normalized using function CURR_TO_DECFLOAT_AMOUNT.
  • my_calcQuan is a calculated quantity of type DECFLOAT34 and it requires a calculated unit reference.
  • AmountAddition is a field that adds two amount fields. The result is an amount field again and a new currency key needs to be assigned.
  • newCalcQuan multiplies a calculated quantity with a number. A calculated unit reference is required. Each calculated unit can be used only once in a view and therefore, a new calculated unit is assigned.





BAL_S_LOG - Application Log: Log header data   Addresses (Business Address Services)  
This documentation is copyright by SAP AG.

Length: 11492 Date: 20240511 Time: 132537     sap01-206 ( 129 ms )