SQL Functions for Numeric Values

The following table shows the numeric SQL functions supported by ABAP CDS and Open SQL. The last two columns indicate where a function can be used.

 SQL Function Result ABAP CDS Open SQL ABS(arg) Absolute amount of arg. x x CEIL(arg) Smallest integer number not less than the value of arg. x x DIV(arg1, arg2) Integer part of the division of arg1 by arg2 The sign is assigned after the amounts are divided; positive if the arguments have the same sign, and negative if the arguments have different signs. Exception: arg2 has the value 0. x x DIVISION(arg1, arg2, dec) Division of arg1 by arg2 The result is rounded to dec decimal places. x x FLOOR(arg) Largest integer number not greater than the value of arg. x x MOD(arg1, arg2) Positive or negative integer remainder of the division of arg1 by arg2. x x ROUND(arg, pos) Rounded value of arg. If pos is greater than 0, the value is rounded to the position pos on the right of the decimal separator. If this is not the case, position abs(pos)+1 to the left of the decimal separator is rounded. This results in a 0 if the number of places is not sufficient. x x

Descriptions of the potential operands and data types can be found the corresponding documentation for ABAP CDS and Open SQL.

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.

Example

The following table shows the results of integer divisions and their integer remainders in SQL. See also the example for the ABAP operators DIV and MOD.

 expr1 expr2 DIV MOD 7 3 2 1 -7 3 -2 -1 7 -3 -2 1 -7 -3 2 -1