SAP NetWeaver AS ABAP Release 752, ©Copyright 2017 SAP AG. All rights reserved.ABAP - Keyword Documentation → ABAP - Reference → Processing External Data → ABAP Database Accesses → Open SQL → Open SQL - Operands and Expressions → Open SQL - Conditions sql_cond → sql_cond - rel_exp for Statements →
sql_cond - LIKE
... operand1 [NOT] LIKE operand2 [ESCAPE esc] ...
This relational expression is true if the value of the operand operand1 matches (does not match) the pattern in the operand operand2.
The data type of operand1 can be one of the dictionary types CHAR, NUMC, CLNT, LANG, DATS, TIMS, ACCP, CUKY, UNIT, or SSTRING. The data type of operand2 must be c or string. The content of operand2 should match the data type of operand1 in accordance with the rules for lossless assignments. This is also checked by the strict modes of the syntax check from Release 7.40, SP08 and can raise an exception.
A pattern in operand2 is defined using the following wildcard characters:
The pattern is case-sensitive. Trailing blanks in operand2 are ignored. This also applies in particular to operands of the type string with trailing blanks that are otherwise respected in ABAP.
If the pattern in operand2 consists of precisely one "%" character, the evaluation of the condition in the database interface is optimized so that the condition is not passed to the database and that, instead, operand1 LIKE '%' is always true regardless of the content of operand1 and operand1 NOT LIKE '%' is always false.
Full text search in a table with text columns.
DATA srch_str TYPE string.
cl_demo_input=>request( CHANGING field = srch_str ).
IF srch_str IS INITIAL.
srch_str = '%' && srch_str && '%'.
WHERE id = 'SD' AND
object LIKE 'AB%' AND
langu = @sy-langu AND
typ = 'E' AND
doktext LIKE @srch_str
INTO TABLE @DATA(text_tab)
UP TO 100 ROWS.
IF sy-subrc = 0.
cl_demo_output=>display( text_tab ).
Pattern synchronization for a numeric column of the table DEMO_EXPRESSIONS. A CAST expression is used here to create the required character-like data type.
DELETE FROM demo_expressions.
INSERT demo_expressions FROM TABLE @(
VALUE #( ( id = 'X' num1 = 111 )
( id = 'Y' num1 = 222 )
( id = 'Z' num1 = 333 ) ) ).
SELECT FROM demo_expressions
FIELDS id, num1
WHERE CAST( num1 AS CHAR ) LIKE '2%'
INTO TABLE @DATA(result).
cl_demo_output=>display( result ).
... ESCAPE esc.
The addition ESCAPE can be used to define a single-character escape character. esc expects a flat character-like data object with the length 1 containing the escape character. A literal or a host variable prefixed with @ can be specified. In the pattern in operand2, the escape character in esc 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 in operand2 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 pooled tables.
To search for the pattern '100%', the following expression can be used with # as the escape character.