SAP NetWeaver AS ABAP Release 751, ©Copyright 2017 SAP AG. All rights reserved.
ABAP - Keyword Documentation → ABAP - Dictionary → ABAP CDS in ABAP Dictionary → ABAP CDS - Data Definitions → ABAP CDS - DDL for Data Definitions → ABAP CDS - DEFINE VIEW → ABAP CDS - SELECT → ABAP CDS - SELECT, Built-In Functions → ABAP CDS - sql_functions →ABAP CDS - Numeric Functions
The following table shows the possible numerical SQL functions in a CDS view, plus the requirements made on the arguments. The meaning of the functions can be found under SQL Functions for Numeric Values.
Function | Valid Argument Types | Result Type |
ABS(arg) | INT1, INT2, INT4, INT8, DEC, CURR, QUAN, FLTP | Data type of arg |
CEIL(arg) | INT1, INT2, INT4, INT8, DEC, CURR, QUAN, FLTP | INT4, INT8 (if arg is of type INT8) |
DIV(arg1, arg2) | INT1, INT2, INT4, INT8, DEC, CURR, QUAN without decimal places. | Data type arg1, where DEC, CURR and QUAN are implemented after INT4 |
DIVISION(arg1, arg2, dec) | arg1, arg2:
INT1,
INT2,
INT4,
INT8,
DEC,
CURR,
QUAN dec: Integer numeric literal greater than or equal to 0 and not greater than the maximum value of 6 and the length of arg2 plus the number of decimal places of arg1 plus 1 |
DEC with dec decimal places. The length of the result is the length of arg1 minus the decimal places in arg1 plus the decimal places in arg2 plus dec. This value must not be greater than 31. |
FLOOR(arg) | INT1, INT2, INT4, INT8, DEC, CURR, QUAN | Data type of arg for the integer types, else DEC without decimal places |
MOD(arg1, arg2) | INT1, INT2, INT4, INT8 | Data type of arg1 |
ROUND(arg, pos) | arg: INT1,
INT2,
INT4,
INT8,
DEC,
CURR,
QUAN pos: Literal, field of a data source or input parameter of type INT1, INT2, INT4 |
Data type of arg, where INT1 and INT2 are transformed to INT4 |
The following can be specified as the arguments arg:
Note
The SQL functions DIV and MOD behave differently with respect to the signs than the ABAP operators DIV and MOD. In the SQL function DIV, the amounts of the arguments are divided and then the sign is assigned (positive if the arguments have the same signs and negative if they have different signs). Accordingly, the result of MOD can be negative, so that multiplying the result of DIV by expr2 plus the result of MOD produces the value of expr1. The ABAP operator MOD, on the other hand, only produces positive results. See Example.
Example
The following CDS view applies predefined numeric SQL functions in the SELECT list to columns of the database table DEMO_EXPRESSIONS. The program DEMO_CDS_SQL_FUNCTIONS_NUM uses SELECT to access the view.