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

Performance Tuning Example 7(using a COLLECT statement in the LOOP)

$
0
0

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



REPORT ZHIS_TUN_008_BEFORE.

 

DATA : BEGIN OF  IT_VBAK  OCCURS 0,

               ERDAT      TYPE VBAK-ERDAT,

               NETWR      TYPE VBAK-NETWR,

               WAERK      TYPE VBAK-WAERK,

            END OF  IT_VBAK.

 

DATA : BEGIN OF  IT_VBAK2  OCCURS 0,

               ERDAT      TYPE VBAK-ERDAT,

               NETWR      TYPE VBAK-NETWR,

               WAERK      TYPE VBAK-WAERK,

            END OF  IT_VBAK2.

 

DATA : WA_VBAK LIKE IT_VBAK.

 

SELECT ERDAT NETWR WAERK

  FROM VBAK INTO TABLE IT_VBAK.

 

LOOP AT IT_VBAK INTO WA_VBAK .

   MOVE-CORRESPONDING: WA_VBAK TO IT_VBAK2.

   COLLECT IT_VBAK2.

ENDLOOP.

 

WRITE :/ LINES( IT_VBAK2 ).

 

 

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



img_7_1.JPG

 

 

 

The source code of using the 'GROUP BY' as follows, can be solved in the execution of one query.

 

 

REPORT ZHIS_TUNING_008_AFTER.

 

DATA : BEGIN OF  IT_VBAK2  OCCURS 0,

               ERDAT      TYPE VBAK-ERDAT,

               NETWR      TYPE VBAK-NETWR,

               WAERK      TYPE VBAK-WAERK,

            END OF  IT_VBAK2.

 

SELECT ERDAT SUM( NETWR ) AS NETWR WAERK

  FROM VBAK INTO TABLE IT_VBAK2

GROUP BY ERDAT WAERK.

 

WRITE :/ LINES( IT_VBAK2 ).

 

img_7_2.JPG

 

'DB: OPEN' time was slightly increased but 'DB: Fetch' time and 'INTERNAL PROCESSING BLOCKS' TIME is decreased

Because it sends only the final result


Viewing all articles
Browse latest Browse all 831

Trending Articles



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