SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.ABAP Keyword Documentation → ABAP - Reference → Processing External Data → ABAP Database Accesses → Open SQL → Open SQL - Read Accesses → SELECT → SELECT - WHERE → WHERE - sql_cond →
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 dobj. It is not possible to specify a column ID for dobj. The data types of the column 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 and col NOT LIKE '%' is always false.
Full-text search in a text table.
PARAMETERS srch_str TYPE c LENGTH 20.
srch_str = '%' && srch_str && '%'.
WHERE doktext LIKE @srch_str
INTO TABLE @DATA(text_tab).
... ESCAPE esc.
The addition ESCAPE can be used to define an escape character. esc must be a flat character-like data object with length one, whose content is used as an escape character. esc 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 pooled tables.
To search for the pattern '100%', the following expression can be used with # as the escape character.