Quantcast
Channel: SCN : All Content - ABAP for SAP HANA
Viewing all articles
Browse latest Browse all 831

Performance Tuning Example 3(using a Delete statement in the LOOP)

$
0
0

Source code below is an example of using the 'Delete' statement in the loop.


REPORT ZHIS_TUN_003_BEFORE.

 

DATA IT_EKKO TYPE TABLE OF EKKO WITH HEADER LINE.


SELECT * APPENDING CORRESPONDING FIELDS OF TABLE IT_EKKO

FROM EKKO.


SORT IT_EKKO BY BSTYP BSART EBELN.


LOOP AT IT_EKKO.

   DATA: L_PSTYP TYPE PSTYP.

   CLEAR: L_PSTYP.

  

  SELECT SINGLE PSTYP INTO L_PSTYP

   FROM EKPO

   WHERE EBELN EQ IT_EKKO-EBELN.


   IF L_PSTYP EQ '7'.

       DELETE IT_EKKO.

       CONTINUE.

   ENDIF.


ENDLOOP.


WRITE:/ LINES( IT_EKKO ) .

 

The results of analysis of the source code of the above in RUNTIME ANALYSIS are as follows:

 

img_3_1.JPG

 

It took most of the work time in the ‘DB: OPEN’.

 

 

 

It took a long time because of 'SELECT' statement in the loop

 

The following is the source code that uses the 'SUBQUERY' in order to improve this

 

 

REPORT ZHIS_TUN_003_AFTER.

 

DATA IT_TAB TYPE TABLE OF EKKO WITH HEADER LINE.

 

SELECT * APPENDING CORRESPONDING FIELDS OF TABLE IT_TAB

FROM EKKO

WHERE EBELN NOT IN ( SELECT EBELN FROM EKPO WHERE PSTYP = 7 ).

 

WRITE:/ LINES( IT_TAB ) .

 

img_3_2.JPG

 

 

If possible, do not the SELECT in LOOP and Use 'JOIN' or 'SUBQUERY' can improve performance.


Viewing all articles
Browse latest Browse all 831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>