ABAP - Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP Database Accesses →  Open SQL →  Open SQL - Reads →  SELECT clauses →  SELECT - WHERE →  WHERE - sql_cond → 

Quick Reference

sql_cond - IN subquery

Syntax

... operand [NOT] IN ( SELECT subquery_clauses [UNION ...] ) ...

Effect

Search for an operand operand in the result set of a subquery. The clauses in the subquery subquery_clauses must constitute a scalar subquery. The language element UNION can be used to combine the result sets of multiple subqueries. In this case, additional rules query_clauses apply for specifying clauses.

The expression is true if the value of the operand operand is (is not) contained in the results set of the scalar subquery. Columns and SQL expressions can be specified for operand. This covers literals, host variables, and host expressions.

Note

When an SQL expression occurs on the left side, the syntax check is performed in a strict mode, which handles the statement more strictly than the regular syntax check.

Example

Reads the geographical latitude and longitude of a city from the database table SGEOCITY, where this city is the city of origin of a flight in the database table SPFLI.

PARAMETERS: carr_id TYPE spfli-carrid,
            conn_id TYPE spfli-connid.

DATA: city  TYPE sgeocity-city,
      lati  TYPE p LENGTH 8 DECIMALS 2,
      longi TYPE p LENGTH 8 DECIMALS 2.

SELECT SINGLE city, latitude, longitude
         FROM sgeocity
         WHERE city IN ( SELECT cityfrom
                                FROM spfli
                                WHERE carrid = @carr_id AND
                                      connid = @conn_id )
         INTO (@city, @lati, @longi).