In ``++SELECT ... FOR ALL ENTRIES++`` queries there are two internal tables: the driver internal table, and the target internal table. For each entry in the driver table some data from a database table is stored in the target internal table. 


Most of the time, starting by sorting the content of the driver internal table offers improved performance. Indeed in such cases, from one request to another, the data read from the database tends to be much the same, and so for instance the use of database caching is maximised. 


== Noncompliant Code Example

[source,abap]
----
SELECT carrid , connid , seatsocc FROM flights
INTO TABLE seatsocc_tab                  		
FOR ALL ENTRIES IN conn_tab  
WHERE carrid = conn_tab-carrid
AND connid = conn_tab-connid
----


== Compliant Solution

[source,abap]
----
SORT conn_tab BY carrid
...
SELECT carrid , connid , seatsocc FROM flights
INTO TABLE seatsocc_tab                  		
FOR ALL ENTRIES IN conn_tab  
WHERE carrid = conn_tab-carrid
AND connid = conn_tab-connid
----

ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

include::message.adoc[]

endif::env-github,rspecator-view[]
