sql_cond - LIKE
... col [NOT] LIKE dobj [ESCAPE esc] ...
This expression is true if the value of the column
col fits (does not fit) the pattern in the
host variable or the literal
It is not possible to specify a column ID for
dobj. The data types of the
col and the data object
dobj must be character-like.
The name of a host variable should be prefixed with the escape character
@. The content of
dobj should match the data type of the column in accordance with the rules for
lossless assignments. This is checked by the
strict modes of the syntax check from Release 7.40, SP08 and can raise an exception.
Wildcard characters can be used to create the pattern in
dobj, where "%"
represents any character string, even an empty one, and "_" represents any character. It is case-sensitive.
Trailing blanks in
dobj are ignored. This is also valid in particular for data objects of the type
string whose trailing blanks are otherwise respected in ABAP.
If the pattern in
dobj consists of precisely one "%" character, the
WHERE condition in the database interface is optimized so that the condition is not passed to
the database and that, instead,
col LIKE '%' is always true regardless of the content of
col NOT LIKE '%' is always false.
- The use of the wildcard characters "_" and "%" corresponds to the standard of SQL. Elsewhere in ABAP, the wildcard characters "+" and "*" are used in similar relational expressions, in particular when selection tables are used.
- Do not use patterns that are closed by wildcard characters to search for trailing blanks. The semantics of searches of this type are dependent on the database system that is used and in general do not produce the desired result.
- Due to the Open SQL-specific optimization,
col LIKE '%'is also true if the column
colcontains null values.
col LIKE '%'is used in the
ONcondition of a join, nothing is optimized and the condition is passed to the database instead.
Full-text search in a text table.
PARAMETERS srch_str TYPE c LENGTH 20. srch_str = '%' && srch_str && '%'. SELECT * FROM doktl WHERE doktext LIKE @srch_str INTO TABLE @DATA(text_tab).
... ESCAPE esc.
ESCAPE can be used to define an
esc must be a
object with length one, whose content is used as an escape character.
is always accessed like a data object of the data type
c of the length 1.
An escape character may only be placed before a wildcard character or before the escape character itself. In this case, these lose their special meaning.
If an escape character is not placed in front of a valid character, an exception of the class CX_SY_OPEN_SQL_DB is raised. The addition
ESCAPE cannot be used when reading
- One of the wildcard characters "_" and "%" can be specified as an escape character
esc, but is not recommended for reasons of readability.
- If the pattern in
dobjis created dynamically or comes from outside of the program, care must be taken that any escape characters it contains are not placed in front of characters other than "_", "%", or the escape character itself. To prevent an exception, escape characters that are part of the patter must be escaped using themselves before being used.
To search for the pattern '100%', the following expression can be used with
# as the escape character.
... LIKE '100#%' ESCAPE '#' ...