Search code examples
abapopensql

Negate FOR ALL ENTRIES in SELECT query?


I want to fetch those records from transparent table that do not exist in the FOR ALL ENTRIES itab.

Whereas default logic is to include those entries which exist in the internal table, I want to exclude them. I want some type of FOR ALL ENTRIES NOT IN statement.

Is there any workaround?


Solution

  • Well, after 8 years of idle I can propose possible solution for my problem.

    Since release 7.52 ABAP allows putting itab as data source for SELECT statement, so the above task can be simplified to appending NOT EXISTS subquery with FOR ALL ENTRIES itab as data source:

    Sample coding:

    * filling FOR ALL ENTRIES table
    SELECT *
      FROM spfli
      INTO TABLE @DATA(lt_exclude_FAE)
     WHERE carrid = s~carrid AND
           connid = s~connid AND
         cityfrom = 'NEW YORK'
    
    * excluding FAE rows
    SELECT *
       FROM sflight AS s
       WHERE seatsocc < s~seatsmax AND
         NOT EXISTS ( SELECT  *
                        FROM @lt_exclude_FAE AS exclude
                       WHERE carrid = s~carrid AND
                             connid = s~connid AND
                           cityfrom = s~cityfrom )
       INTO TABLE @DATA(flights_wo_ny).
    

    Though, now this works surely only on HANA database, and maybe on couple of others.