Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP Database Accesses →  Open SQL →  Open SQL - Read Accesses →  SELECT →  SELECT - result →  SELECT - select_list →  SELECT - col_spec →  SELECT - sql_exp 

sql_exp - sql_arith_func

Other versions: 7.31 | 7.40 | 7.54

Syntax


... func( arg1[, arg2]... ) ...

Effect

Calls an arithmetic function func as an operand of an expression in Open SQL. The arguments of the function are specified as a comma-separated list in parentheses. A blank must be placed before the opening parenthesis and after the closing parenthesis.

The following table summarizes the arithmetic functions that can be specified as SQL expressions.

Syntax Valid Argument Types Result Result Type
abs( arg ) All numeric types except decimal floating point numbers Absolute Value Dictionary Type of the Argument
ceil( arg ) Dictionary types DEC, CURR, and QUAN plus the ABAP type p with decimal places Smallest integer number not less than the value of arg Dictionary type DEC without decimal places in the length of the result
floor( arg ) Dictionary types DEC, CURR, and QUAN plus the ABAP type p with decimal places Largest integer number not greater than the value of arg Dictionary type DEC without decimal places in the length of the result
div( arg1,arg2 ) Dictionary types INT1, INT2, and INT4 plus DEC, CURR, and QUAN without decimal places ABAP typesb, s, and i plus p without decimal places Integer part of the division of arg1 by arg2 Dictionary type of arg1
mod( arg1,arg2 ) Dictionary types INT1, INT2, and INT4 plus DEC, CURR, and QUAN without decimal places ABAP typesb, s, and i plus p without decimal places Integer remainder of the division of arg1 by arg2 Dictionary type of arg2

The arguments can be columns, host variables, literals or any expressions constructed from these three elements.

If an argument of an arithmetic function has the null value, the result of the full arithmetic function is the null value.


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 with arg2 plus the result of mod produces the value of arg1. 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 Open SQL. See also the example for the ABAP operators DIV and MOD.

arg1 arg2 div mod
7 3 2 1
-7 3 -2 -1
7 -3 -2 1
-7 -3 2 -1