Negate FOR ALL ENTRIES in SELECT query?
Question
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.
OTHER TIPS
I don't think if it is possible. I would use ranges for that. If this is not suitable, loop+read table can be used.
You can use simple Query for this issue.
Check this coding...
TABLES : table1 , table2 .
DATA : it_table1 TYPE STANDARD TABLE OF table1 ,
it_table2 TYPE STANDARD TABLE OF table2 ,
wa_table1 TYPE table1 ,
wa_table2 TYPE table2 .
SELECT * FROM table1 INTO CORRESPONDING FIELDS OF TABLE it_table1 .
LOOP AT it_table1 INTO wa_table1 .
SELECT field1 FROM table2 INTO CORRESPONDING FIELDS OF TABLE it_table2 WHERE field2 = wa_table1-field1 .
IF sy-subrc = 0 .
delete TABLE it_table1 FROM wa_table1 .
ENDIF.
ENDLOOP.