ABAP Keyword Documentation → ABAP − Reference → Processing External Data → ABAP Database Access → ABAP SQL → ABAP SQL - Operands and Expressions → ABAP SQL - SQL Expressions sql_exp → sql_exp - sql_func → ABAP SQL - Built-In Functions sql_func → ABAP SQL - SQL Functions
sql_exp - sql_num_func
Other versions:
7.31 | 7.40 | 7.54
Syntax
... func( arg1[, arg2] ... ) ...
Effect
Calls an numeric function func
as an
SQL expression or operand of an expression in ABAP SQL.
The arguments arg1
, arg2
, ... of the function
are specified as a comma-separated list in parentheses. A blank must be placed after the opening parenthesis and before the closing parenthesis.
The following table shows the numeric functions that can be specified as SQL expressions and the requirements made on the arguments. The meaning of the functions can be found under SQL Functions for Numeric Values. The value "x" in the Table Buffer column indicates that the function can be executed in the table buffer and that the use of this function does not bypass table buffering.
Syntax | Valid Argument Types | Result Type | Table Buffer |
---|---|---|---|
ABS( sql_exp ) |
All numeric types except the replacement types for decimal floating point numbers | Type of the argument | x |
CEIL( sql_exp ) |
DECFLOAT16 and DECFLOAT34 as well as DEC, CURR, and QUAN with decimal places | DEC without decimal places in the length of the result | x |
DIV( sql_exp1,sql_exp2 ) |
INT1, INT2, INT4, and INT8 plus DEC, CURR, and QUAN without decimal places | Type of the argument with the greatest value range. | x |
DIVISION( sql_exp1,sql_exp2,dec ) |
sql_exp1 , sql_exp2 : INT1, INT2, INT4, INT8, DEC, CURR, and QUAN |
||
dec :Literal orhost constant withABAP type b , s , i , int8 greater than or equal to 0 andnot greater than the maximum value of 6 and the length of sql_exp2 plus the number of decimal places of sql_exp1 plus 1 |
DEC with dec decimal places. The length of the result is the length ofsql_exp1 minus the decimal places in sql_exp1 plus the decimal places in sql_exp2 plus dec . This value must not be greater than 31. |
- | |
FLOOR( sql_exp ) |
DECFLOAT16 and DECFLOAT34 as well as DEC, CURR, and QUAN with decimal places | DEC without decimal places in the length of the result | x |
MOD( sql_exp1,sql_exp2 ) |
INT1, INT2, INT4, and INT8 plus DEC, CURR, and QUAN without decimal places | Type of the argument with the greatest value range. | x |
ROUND( sql_exp,pos ) |
sql_exp : INT1, INT2, INT4, INT8, DEC, CURR, and QUAN |
||
pos : INT1, INT2, and INT4 |
Type of sql_exp, where INT1 and INT2 are updated after INT4, and CURR and QUAN are updated after DEC. | - |
The arguments sql_exp
, sql_exp1
, sql_exp3
, and pos
can be any
SQL expressions with the matching data types. The possible types are specified as built-in
dictionary types. The possible data types for literals, host variables, and host expressions are the ABAP types
assigned to the dictionary types above.
If an argument of a numeric function has the null value, the result of the full numeric 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
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
Conversion of flight time from minutes to hours.
SELECT FROM spfli
FIELDS carrid,
connid,
DIVISION( fltime,60,2 ) AS fltime
ORDER BY carrid, connid
INTO TABLE @DATA(result).
cl_demo_output=>display( result ).