Professional Documents
Culture Documents
doc
Applies to:
ABAP
Summary
This article explains how to improve the performance of FOR ALL ENTRIES query
Author(s): Ashim Chowdhury Company: Tata Consultancy Services Ltd. Created on: 12 September 2006
Author Bio
Ashim Chowdhury is an SAP Technical consultant with Tata Consultancy, India. He works in the SAP technical area (ABAP, Net weaver, XI).
Table of Contents
Applies to: ........................................................................................................................................ 1 Summary.......................................................................................................................................... 1 Author Bio ........................................................................................................................................ 1 Improving performance of FOR ALL ENTRIES query..................................................................... 3 Example code and performance data comparison: ..................................................................... 3 Comparison result: ....................................................................................................................... 4 Conclusion: ...................................................................................................................................... 5 Disclaimer and Liability Notice......................................................................................................... 6
Example code and performance data comparison: For the purpose of comparison of the query performance a dummy program has been used. I have used two tables, MARA and MAKT. First try to get the Materials from table MARA and then for all entries in MARA, try to get the data from MAKT. To make the performance difference more prominent the records in the driver table has been duplicated. Here is the source code:
DATA: it_mara TYPE wa_mara TYPE it_makt TYPE wa_makt TYPE it_temp_mara wa_temp_mara STANDARD TABLE OF mara, mara, STANDARD TABLE OF makt, makt, TYPE STANDARD TABLE OF mara, TYPE mara.
* Get all the records from MARA SELECT * FROM mara INTO TABLE it_temp_mara. IF sy-subrc = 0. IF it_temp_mara[] IS NOT INITIAL. * Duplicate the driver table with the data do 100 times. append lines of it_Temp_mara to it_mara. enddo. IF it_mara[] IS NOT INITIAL. * Select MAKT perform select_makt. sort it_mara by matnr. perform select_makt.
After deleting duoplicateentries DELETE ADJACENT DUPLICATES FROM it_mara COMPARING matnr. perform select_makt.
ENDIF. ENDIF. ENDIF. *&---------------------------------------------------------------------* *& Form select_makt *&---------------------------------------------------------------------* * Select data friom MAKT *----------------------------------------------------------------------* form select_makt . DATA: t1 TYPE i, t2 TYPE i, tmin TYPE i. refresh it_makt[]. GET RUN TIME FIELD t1. SELECT * FROM makt INTO TABLE it_makt FOR ALL ENTRIES IN it_mara WHERE matnr = it_mara-matnr. GET RUN TIME FIELD t2. tmin = t2 - t1. tmin = tmin . WRITE:/ ' Time(ms) = ', tmin. Endform.
Comparison result: This program has been run in a R3 system (ABAP release 6,20) having 124 materials. For better demonstration of the effect, the records in it_mara has been duplicated by 100 times.
No of run 1 2 3
Records in MARA
Time required ( mili-seconds) After Sort 942 1126 929 999 After sort and delete adjacent duplicates 19 14 12 15
From the result it is quite evident that using a sorted and unique driver table will improve the performance of a select for all entries query (especially if there are duplicate records in the driver table).
Conclusion:
Using a sorted and unique driver table boost the performance of FOR ALL ENTRIES query, especially in cases where driver table has many duplicate rows.