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:


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.


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.

@AbapCatalog.sqlViewName: 'DEMO_CDS_NUMFUNC'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view demo_cds_sql_functions_num
  as select from
      abs(       num1          ) as r_abs,
      ceil(      fltp1         ) as r_ceil,
      floor(     dec1          ) as r_floor,
      div(       num1, num2    ) as r_div,
      mod(       num1, num2    ) as r_mod,
      division(  dec2, dec3, 3 ) as r_division,
      round(     dec3, 2       ) as r_round