Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP Database Access →  ABAP SQL →  ABAP SQL - Operands and Expressions →  ABAP SQL - SQL Conditions sql_cond →  sql_cond - rel_exp for Statements 

sql_cond - EXISTS

Other versions: 7.31 | 7.40 | 7.54

Syntax


... EXISTS ( SELECT subquery_clauses [
UNION ...] ) ...

Effect

Checks the results set of a subquery. The relational expression is true when the results set of the subquery defined by the clauses subquery_clauses contains at least one row. The expression is possible for any results sets that can be defined using subquery clauses subquery_clauses. The language element UNION can be used to combine the results sets of multiple subqueries. In this case, special rules query_clauses apply for specifying clauses.


Note

The specified columns in the SELECT list of the subquery are not important for EXISTS. Therefore, explicit lists are not useful. It is a good idea to have a literal as the only specified column.


Example

Extracts all available flights leaving from New York from the database table SFLIGHT to the internal table free_flights.

DATA city         TYPE spfli-cityfrom VALUE 'NEW YORK'. 

SELECT * 
       FROM sflight AS s 
       WHERE seatsocc < s~seatsmax AND 
             EXISTS ( SELECT 'X' 
                            FROM spfli 
                            WHERE carrid   =  s~carrid AND 
                                  connid   =  s~connid AND 
                                  cityfrom = @city ) 
       INTO TABLE @DATA(free_flights).