Skip to content

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

sql_cond - IN seltab

Other versions: 7.31 | 7.40 | 7.54

Syntax


... col [NOT] IN seltab ...

Effect

This expression is true if the value of the column col is (not) in the result set described in the rows of the selection table seltab. Any internal table with a row type that corresponds to that of a selection table can be specified as the selection table seltab. This includes, in particular, ranges tables.

The selection table is evaluated in the same way as in logical expressions apart from the fact that in comparisons with the operators CP and NP the WHERE condition is case-sensitive, whereas in other logical expressions it is not. The wildcard characters "*" and "+" of the selection options "CP" and "NP" are converted to the OpenSQL wildcard characters "%" and "", whereby the escape character "#" is also handled correctly. If "%" and "" are contained in the template, an OpenSQL escape character is generated.


Notes

  • If the selection table contains invalid values, an exception that cannot be handled is raised.

  • If the selection table is initial, the expression is always true. If no conditions are specified apart from the expression above, all rows of the database table are selected if the selection table is initial.

  • The conditions specified in the selection table are passed by the database interface to the database as SQL statement input values. The maximum number of input values depends on the database system and is usually between 2000 and 10000. If the maximum number is exceeded an exception of the class CX_SY_OPEN_SQL_DB is raised.

Example

A selection table is filled as follows (the order of the rows is not important):

SIGN  OPTION  LOW              HIGH
---------------------------------------
I     EQ      01104711
I     BT      10000000         19999999
I     GE      90000000
E     EQ      10000911
E     BT      10000810         10000815
E     CP      1%2##3#+4++5*

The following WHERE condition is generated from this:

... ( ID = '01104711'                      OR
      ID BETWEEN '10000000' AND '19999999' OR
      ID >= '90000000' )                     AND
    ID <> '10000911'                         AND
    ID NOT BETWEEN '10000810' AND '10000815' AND
    ID NOT LIKE '1#%2##3+4__5%' ESCAPE '#'   ...


Example

Reads flights with a primary key that corresponds to the user entries on the selection screen.

DATA spfli_wa TYPE spfli. 

SELECT-OPTIONS: s_carrid FOR spfli_wa-carrid NO INTERVALS 
                                           NO-EXTENSION, 
                s_connid FOR spfli_wa-connid NO INTERVALS 
                                            NO-EXTENSION. 

SELECT SINGLE * 
       FROM spfli 
       INTO spfli_wa 
       WHERE carrid IN s_carrid AND 
             connid IN s_connid.

Continue

Selection Tables in the WHERE Clause