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_string_func
Other versions:
7.31 | 7.40 | 7.54
Syntax
... func( arg1[, arg2] ... ) ...
Effect
Calls a string 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 string 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 Strings. 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 |
---|---|---|---|
CONCAT( sql_exp1,sql_exp2 ) |
See below | SSTRING if an argument has the type SSTRING, else CHAR with the length of the result. | x |
CONCAT_WITH_SPACE( sql_exp1,sql_exp2,spaces ) |
sql_exp1 , sql_exp2 : see below |
||
spaces :Literal orhost constant with theABAP type b , s , i , or int8 greater than 0 and less than or equal to 1331 |
SSTRING if an argument has the type SSTRING, else CHAR with the length of the result. | x | |
INSTR( sql_exp,sub ) |
sql_exp : see below |
||
sub :Literal orhost constant with theABAP type c , n , d , or t |
INT4 | - | |
LEFT( sql_exp,len ) |
sql_exp : see below |
||
len :Literal orhost constant with theABAP type b , s , i , or int8 greater than 0 and less than or equal to 1333 |
SSTRING if sql_exp has the type SSTRING, else CHAR with the length of the result |
- | |
LENGTH( sql_exp ) |
See below | INT4 | - |
LOWER( sql_exp ) |
See below | SSTRING if sql_exp has the type SSTRING, else CHAR with the length of sql_exp |
- |
LPAD( sql_exp,len,src ) |
sql_exp : see below |
||
len :Literal orhost constant with theABAP type b , s , i , or int8 greater than 0 and less than or equal to 1333 |
|||
src :Literal orhost constant with theABAP type c , d , t , n , or string with a maximum of 1333 characters |
SSTRING if sql_exp has the type SSTRING, else CHAR with the length of len . |
- | |
LTRIM( sql_exp,char ) |
sql_exp : see below |
||
char :Literal orhost constant with theABAP type c or n with the length 1 |
SSTRING if sql_exp has the type SSTRING, else CHAR with the length of sql_exp |
- | |
REPLACE( sql_exp1,sql_exp2,sql_exp3 ) |
See below | SSTRING if an argument has the type SSTRING, else CHAR with the maximum possible length of the result. | - |
RIGHT( sql_exp,len ) |
sql_exp : see below |
||
len :Literal orhost constant with theABAP type b , s , i , or int8 greater than 0 and less than or equal to 1333 |
SSTRING if sql_exp has the type SSTRING, else CHAR with the length of the result |
- | |
RPAD( sql_exp,len,src ) |
sql_exp : see below |
||
len :Literal orhost constant with theABAP type b , s , i , or int8 greater than 0 and less than or equal to 1333 |
|||
src :Literal orhost constant with theABAP type c , d , t , n , or string with a maximum of 1333 characters |
SSTRING if sql_exp has the type SSTRING, else CHAR with the length of len . |
- | |
RTRIM( sql_exp,char ) |
sql_exp : see below |
||
char :Literal orhost constant with theABAP type c or n with the length 1 |
SSTRING if sql_exp has the type SSTRING, else CHAR with the length of sql_exp |
- | |
SUBSTRING( sql_exp,pos,len ) |
sql_exp : see below |
||
pos : Literal,host variable, orhost expression with theABAP type b , s , i , int8 |
|||
len :Literal orhost constant with theABAP type b , s , i , int8 |
SSTRING if sql_exp has the type SSTRING, else CHAR with the length of len |
x | |
UPPER( sql_exp ) |
See below | SSTRING if sql_exp has the type SSTRING, else CHAR with the length of sql_exp |
- |
The arguments sql_exp
, sql_exp1
, sql_exp2
, and sql_exp3
can be any
SQL expressions with the matching data types. The possible data types are the
dictionary types CHAR, CLNT, CUKY, DATS, LANG, NUMC, TIMS, UNIT, and SSTRING. The possible data types for literals, host variables, and host expressions are the ABAP types
assigned to the dictionary types above. The result types are also dictionary types.
If the argument of a string function has the null value, the result of the full string function is the null value.
Notes
- The argument
len
of the functionsRIGHT
andSUBSTRING
must only be a real constant in static clauses. In clauses of an ABAP SQL statement specified in parentheses, the argument can also be a variable evaluated at runtime.
- In the case of the function
REPLACE
, it should be noted that the maximum possible length of the result can be slightly greater than the permitted length of 1333. This produces a syntax error. In general, the maximum possible length is calculated by dividing the length of sql_exp1 by the length of sql_exp2, multiplied by the length of sql_exp3.
Example
The SELECT
statement gets the maximum length of a URL in the database table SCARR.
SELECT FROM scarr
FIELDS MAX( length( url ) ) AS maxlen
INTO @DATA(result).
cl_demo_output=>display( result ).
Example
Concatenates multiple columns of a database table as a character-like column in the program DEMO_SQL_FUNCTION_CONCAT
using CONCAT
. An alignment is specified using LPAD
and RPAD
. A concatenation of this type is not possible using the operator &&
.
SELECT CONCAT_WITH_SPACE( CONCAT( carrid,
LPAD( carrname,21,' ' ) ),
RPAD( url,40,' ' ), 3 ) AS line
FROM scarr
INTO TABLE @DATA(result).