Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP Database Access →  ABAP SQL →  ABAP SQL - Reads →  SELECT clauses 

SELECT - WHERE

Quick Reference

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 WHERE condition. If not, buffering is bypassed.
  • If the data sources are accessed using single record buffering, the conditions joined using AND in the WHERE condition must be specified for all key fields of the primary key. If not, buffering is bypassed.
  • For frequently used SELECT statements with an identical WHERE condition, an index. In WHERE conditions, the fields of the index should be expressed as equality comparisons and joined using the AND operator. All the fields of an index that are behind a field, for which a comparison other than = or EQ is specified in the WHERE clause, cannot be used for searching in the index.
  • It is currently not possible to use aggregate expressions as operands in a WHERE condition. This is only possible in the HAVING clause.
  • The client column of a client-specific data source can still be used in the ON condition if implicit client handling is disabled using the obsolete addition CLIENT 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). 

Executable Examples

Continue

SQL Expressions in the WHERE Condition