ABAP Keyword Documentation → ABAP Dictionary → ABAP CDS in ABAP Dictionary → ABAP CDS - Views → ABAP CDS - DDL Statements → ABAP CDS - DEFINE VIEW → ABAP CDS - SELECT → ABAP CDS - SELECT, Operands and Expressions
ABAP CDS - arith_expr
Other versions:
7.31 | 7.40 | 7.54
Syntax
... [-]operand1 [+|-||/ [-]operand2 [+|-||/ [-]operand3 ... ]] ...
Effect
Arithmetic expression in a SELECT statement of a CDS view in ABAP CDS. An arithmetic expression uses arithmetic operators to calculate a numeric value from numeric operands. Possible operators:
Operator | Meaning |
---|---|
+ | Addition of the operands |
- | Subtraction of the right operand from the left |
* | Multiplication of the operands |
/ | Division of the left operand by the right |
An -
in front of an operand multiplies it by -1. The data type of the operands must be numeric and the following can be specified:
- Numeric fields of a data source data_source of the current CDS view
- Parameter with numeric data type
- Path expressions that identify a numeric field of a data source data_source
- Predefined functions that return a numeric type.
- Casting expressions that return a numeric type.
- When a division is performed, the operands of type FLTP or numeric literals with decimal places and the right operand cannot have the value 0.
The subexpressions of an arithmetic expression can be compounded with parentheses (...).
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.
Arithmetic expressions can be used as elements of a SELECT list, where they need alternative element names, which have been defined using AS.
Note
When a division is performed with two numbers of type DEC, the SQL function DIVISION can be used.
Example
SELECT list of a CDS view with arithmetic expressions.
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
}