ABAP Keyword Documentation → ABAP - Reference → Processing External Data → ABAP Database Accesses → Open SQL → Open SQL - Read Accesses → SELECT
SELECT - WHERE
Other versions: 7.31 | 7.40 | 7.54
Syntax
... [FOR ALL ENTRIES IN itab] WHERE sql_cond ...
Effect
The addition WHERE restricts the number of lines included in the result set
by the statement SELECT, by using a logical expression
sql_cond. The logical expression compares the content of columns in the database with the content of
host variables, literals, or with the content
of other columns. The optional addition FOR
ALL ENTRIES can be used to compare the content of a column in the database with a component with all lines of a structured internal table itab.
The logical expression sql_cond is either true, false, or unknown. The expression is unknown if one of the columns involved in the database contains a
null value and is evaluated
with another comparison as IS NULL. A row is only included in the results set if the logical expression is true.
Except for columns of type STRING or RAWSTRING plus LCHR or LRAW or the obsolete VARC, all columns of the database tables or
views specified after
FROM can be evaluated after the WHERE condition. The columns do not necessarily have to be a part of the results set.
Notes
-
The client ID cannot be queried in the
WHEREcondition, if automatic client handling is not deactivated using the additionCLIENT SPECIFIEDafterFROM. This is usually tested by the syntax check. If the client ID is queried in theWHEREcondition andCLIENT SPECIFIEDis not specified (which is sometimes the case when using alternative table names, in joins, and when specified dynamically), automatic client handling is not switched off. In this case, there are two conditions for the client column: the implicit condition of the automatic client handler for the current client and the explicitly specified condition. If the current client is not specified in the explicitly specified condition, the result set is empty. -
The
WHEREcondition of theSELECTstatement described here includes theWHEREconditions of the Open SQL statementsDELETE, OPEN CURSOR, andUPDATE. -
The logical expressions of the
WHEREcondition can also all be used after the additionHAVING, and sometimes in theONcondition of a Join expression after the additionFROM. -
If the database table is accessed with generic
SAP buffering, the buffered area must be fully specified in the
WHEREcondition, otherwise buffering is ignored. -
If the database tables are accessed using single record buffering, the conditions joined using
ANDin the
WHEREcondition must be specified for all key fields of the primary key, otherwise buffering is ignored.