Ansicht
Dokumentation

ABENCDS_F1_ARITHMETIC_EXPRESSION - CDS F1 ARITHMETIC EXPRESSION

ABENCDS_F1_ARITHMETIC_EXPRESSION - CDS F1 ARITHMETIC EXPRESSION

RFUMSV00 - Advance Return for Tax on Sales/Purchases   SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up  
This documentation is copyright by SAP AG.
SAP E-Book

- arith_expr

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

Effect

Arithmetic expression in a SELECT statement of a CDS view. 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 - 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, CURR, QUAN, DECFLOAT16, DECFLOAT34, or FLTP. The following can be specified:

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

The following table shows which data types can be linked using the operators +, -, and * and the data type of the result:

+, -, * INT1 INT2 INT4 INT8 DEC CURR QUAN DECFLOAT16 DECFLOAT34 FLTP
INT1 INT4 INT4 INT4 INT8 DEC CURR QUAN DECFLOAT16 DECFLOAT34 -
INT2 INT4 INT4 INT4 INT8 DEC CURR QUAN DECFLOAT16 DECFLOAT34 -
INT4 INT4 INT4 INT4 INT8 DEC CURR QUAN DECFLOAT16 DECFLOAT34 -
INT8 INT8 INT8 INT8 INT8 DEC CURR QUAN DECFLOAT16 DECFLOAT34 -
DEC DEC DEC DEC DEC DEC CURR QUAN DECFLOAT16 DECFLOAT34 -
CURR CURR CURR CURR CURR CURR CURR DEC DECFLOAT16 DECFLOAT34 -
QUAN QUAN QUAN QUAN QUAN QUAN DEC QUAN DECFLOAT16 DECFLOAT34 -
DECFLOAT16 DECFLOAT16 DECFLOAT16 DECFLOAT16 DECFLOAT16 DECFLOAT16 DECFLOAT16 DECFLOAT16 DECFLOAT16 DECFLOAT34 -
DECFLOAT34 DECFLOAT34 DECFLOAT34 DECFLOAT34 DECFLOAT34 DECFLOAT34 DECFLOAT34 DECFLOAT34 DECFLOAT34 DECFLOAT34 -
FLTP - - - - - - - - - FLTP

The following table shows which data types can be linked using the operator / and the data type of the result:

/ DECFLOAT16 DECFLOAT34 FLTP
DECFLOAT16 DECFLOAT16 DECFLOAT34 -
DECFLOAT34 DECFLOAT34 DECFLOAT34 -
FLTP - - FLTP

Note the following special conditions:

  • If an expression contains an operand of type DEC, CURR or QUAN, 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 /, it must be a floating point expression. This means the operands must be of type DECFLOAT16, DECFLOAT34, FLTP in combinations shown in the table above, or numeric literals with fractional digits. Other numeric data types are not possible. The right operand cannot have the value 0.

Arithmetic expressions can be used as elements of a SELECT list, where 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 with arithmetic expressions.

@AbapCatalog.sqlViewName: 'SALES_ORDER_VW'
define view sales_order as
  select from snwd_so
         association [1..*] to snwd_so_i as _item
           on snwd_so.node_key = _item.parent_key
         { key snwd_so.node_key,
               gross_amount,
               gross_amount - tax_amount as pre_tax_amount,
               cast(gross_amount as abap.fltp)
                 + (cast( -gross_amount as abap.fltp) * 0.03)
                   as reduced_amount,
            cast(gross_amount as abap.fltp) * 0.03 as overall_savings,
            _item.so_item_pos as item_position,
            _item.gross_amount as item_gross_amount,
            cast(_item.gross_amount as abap.fltp) * 0.97 as item_savings
}





CL_GUI_FRONTEND_SERVICES - Frontend Services   Addresses (Business Address Services)  
This documentation is copyright by SAP AG.

Length: 14444 Date: 20240424 Time: 091831     sap01-206 ( 119 ms )