ABAP Keyword Documentation → ABAP − Reference → Processing External Data → ABAP Database Access → ABAP SQL → ABAP SQL - Reads → SELECT clauses
SELECT - WHERE
Other versions: 7.31 | 7.40 | 7.54
Syntax
... WHERE sql_cond ...
Effect
The addition WHERE restricts the number of rows included in the results set by the statement SELECT of a
query, by using a logical expression
sql_cond. A row is only included in the results set if the logical expression is true.
Except for columns of type STRING, RAWSTRING, or GEOM_EWKB, or LCHR and LRAW, all columns of the
data sources specified after
FROM can, as a rule, be evaluated in the WHERE condition of a
query. Special rules apply to some logical expressions. The columns do not necessarily have to be a part of the results set.
Implicit ABAP SQL client handling applies to the WHERE clause. The
client column of a client-specific data source cannot be used as an operand in the WHERE condition.
Notes
-
If the data source is accessed using generic
table buffering, the buffered area must be specified in full in the
WHEREcondition. If not, buffering is bypassed. -
If the data sources are accessed using single record buffering, the conditions joined using
ANDin theWHEREcondition must be specified for all key fields of the primary key. If not, buffering is bypassed. -
For frequently used
SELECTstatements with an identicalWHEREcondition, an index. InWHEREconditions, the fields of the index should be expressed as equality comparisons and joined using theANDoperator. All the fields of an index that are behind a field, for which a comparison other than=orEQis specified in theWHEREclause, cannot be used for searching in the index. -
It is currently not possible to use
aggregate expressions as operands in a
WHEREcondition. This is only possible in theHAVINGclause. -
The client column of a client-specific data source can still be used in the
ONcondition if implicit client handling is disabled using the obsolete additionCLIENT SPECIFIED.
Example
Reads all objects in the ABAP keyword documentation from the table DOKIL using a suitable WHERE condition. Messages of the
code inspector are suppressed using
pseudo comments due to the table buffering bypass.
SELECT FROM dokil
FIELDS object, langu
WHERE id = 'SD' AND
typ = 'E' AND
( object LIKE 'ABAP%' OR
object LIKE 'ABEN%' OR
object LIKE 'DYNP%' ) AND
( langu = 'D' OR langu = 'E' ) "#EC CI_GENBUFF
ORDER BY object, langu "#EC CI_BYPASS
INTO TABLE @DATA(dokil_tab).