SAP NetWeaver AS ABAP Release 750, ©Copyright 2016 SAP AG. All rights reserved.
ABAP - Keyword Documentation → ABAP - Reference → Processing External Data → ABAP Database Accesses → Open SQL → Open SQL - Read Accesses → SELECT → SELECT - WHERE →WHERE - FOR ALL ENTRIES
Syntax
... FOR ALL ENTRIES IN itab WHERE ... col operator itab-comp ...
Effect
If the addition FOR ALL ENTRIES is specified before the language element WHERE of the statement SELECT, the components comp of the internal table itab specified there can be used within sql_cond on the left side of comparisons of a column col with relational operators. The specified component comp must be compatible with the column col. The internal table itab can have a structured or an elementary row type. For an elementary row type, the pseudo component table_line must be specified for comp. The name of the host variable dbcur should be prefixed with the escape character @.
The entire logical expression sql_cond is evaluated for each individual row of the internal table itab. The results set of the SELECT statement is the union set of the results sets produced by the individual evaluations. Rows that appear in duplicate are removed from the results set automatically. If the internal table itab is empty, the entire WHERE condition is ignored and all rows from the database are placed in the results set.
The logical expression sql_cond of the WHERE condition can comprise multiple logical expressions using AND and OR. However, if FOR ALL ENTRIES is specified, there must be at least one comparison with a column of the internal table itab that can be specified statically or dynamically.
The following restrictions apply when using the addition FOR ALL ENTRIES with other additions:
Notes
Example
Gets all flight data for a specified departure city. The relevant airlines and flight numbers are first passed to an internal table entry_tab, which is evaluated in the WHERE condition of the subsequent SELECT statement. This selection could also be carried out in a single SELECT statement by using a join in the FROM clause. Make sure that the table entry_tab is not initial before the SELECT statement is executed using FOR ALL ENTRIES.
DATA p_city TYPE spfli-cityfrom.
cl_demo_input=>request( CHANGING field = p_city ).
TYPES: BEGIN OF entry_tab_type,
carrid TYPE spfli-carrid,
connid TYPE spfli-connid,
END OF entry_tab_type.
TYPES: BEGIN OF result_tab_type,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
fldate TYPE sflight-fldate,
END OF result_tab_type.
DATA: entry_tab TYPE TABLE OF entry_tab_type,
result_tab TYPE SORTED TABLE OF result_tab_type
WITH UNIQUE KEY carrid connid fldate.
SELECT carrid, connid
FROM spfli
WHERE cityfrom = @( to_upper( p_city ) )
INTO CORRESPONDING FIELDS OF TABLE @entry_tab.
IF entry_tab IS NOT INITIAL.
SELECT carrid, connid, fldate
FROM sflight
FOR ALL ENTRIES IN @entry_tab
WHERE carrid = @entry_tab-carrid AND
connid = @entry_tab-connid
ORDER BY PRIMARY KEY
INTO CORRESPONDING FIELDS OF TABLE @result_tab.
cl_demo_output=>display( result_tab ).
ENDIF.