Source code below is an example of using the 'For All Entries' statement
REPORT ZHIS_TUN_002_BEFORE.
DATA: IT_COEP TYPE TABLE OF COEP,
IT_COBK TYPE TABLE OF COBK.
SELECT * INTO CORRESPONDING FIELDS OF TABLE IT_COBK
FROM COBK.
SELECT *
FROM COEP INTO CORRESPONDING FIELDS OF TABLE IT_COEP
FOR ALL ENTRIES IN IT_COBK
WHERE KOKRS = IT_COBK-KOKRS
AND BELNR = IT_COBK-BELNR.
WRITE:/ LINES( IT_COEP ).
The results of analysis of the source code of the above in RUNTIME ANALYSIS are as follows:
It took most of the work time in the ‘DB: OPEN’ and ‘DB: Fetch’
but 'DB: Fetch' time can not improve because the amount of data transferred is large.
Double-click the ‘DB: OPEN’, check the HIT LIST
If the data is large, 'For All Entries' may be generated many DB access.
As a result, It can be confirmed that the execution time is slow
The following is the source code that uses the JOIN in order to improve this.
REPORT ZHIS_TUN_002_AFTER.
DATA: IT_COEP TYPE TABLE OF COEP ,
IT_COBK TYPE TABLE OF COBK .
SELECT * INTO CORRESPONDING FIELDS OF TABLE IT_COEP
FROM COEP AS A INNER JOIN COBK AS B
ON B~KOKRS = A~KOKRS AND B~BELNR = A~BELNR.
WRITE:/ LINES( IT_COEP ) .
Because there was a 'COEP' table only once access, you can see that the execution time is greatly reduced.
(DB:OPEN Runtime : 14,103,513 -> 752)
If the data is large , do not the 'For All Entries' and Use 'JOIN' or 'SUBQUERY' can improve performance.