Skip to content

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 numeric 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, whereDEC,CURR andQUAN are implemented after INT4
DIVISION(arg1, arg2, dec) arg1, arg2:INT1,INT2,INT4,INT8,DEC,CURR,QUAN
dec: integernumeric literal greater than or equal to 0 and notgreater than the maximum value of 6 and the length of arg2 plus the number of decimal places of arg1 plus 1 DEC with decdecimal places. The length of the result is the length of arg1 minus thedecimal 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 orinput parameter of typeINT1,INT2, or INT4 Data type arg: hereINT1 andINT2 are implemented after INT4.

The following can be specified as the arguments arg:

  • Literals of a suitable type. The literal can be prefixed with the name of a domain.
  • The following built-in functions and expressions (if they return a matching type):
  • Type modifications using CAST

Other versions: 7.31 | 7.40 | 7.54


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 built-in 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
    demo_expressions
    {
      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
    }