Monday, July 23, 2007

Performance Tuning - Operation on Internal Table

In development server you may not aware of performance tuning on operation on internal table, but it could become a problem when you are working on internal table containing more 10 thousand rows.

These are tips to improve your program performance.

READ Table WITH Criteria
By default, read command on internal table will read it sequentially. The binary search algorithm helps faster search of a value in an internal table. But you must sort it before use binary search. Binary search repeatedly divides the search interval in half. If the value to be searched is less than the item in the middle of the interval, the search is narrowed to the lower half, otherwise the search is narrowed to the upper half.


SORT TABLE BY field1.

READ TABLE table1 WITH KEY field1 = criteria1 BINARY SEARCH.
Do try it for internal table containing more than 10 thousand rows, you will find it significantly improve performance tuning.

You can apply binary search method to improve performance on nested loop.
Nested loop:


LOOP AT inttab1.
LOOP AT inttab2 WHERE intab2-field1 = intab1-field1.
ENDLOOP.
ENDLOOP.



Replace above code with additional binary search.



SORT inttab2 BY field1.
LOOP AT inttab1.
READ TABLE inttab2 WITH KEY field1 = inttab1-field1 BINARY SEARCH.
CHECK sy-subrc = 0.
LOOP AT inttab2 FROM sy-tabix.
IF inttab2-field1 NE inttab1-field1.
EXIT.
ENDIF.
ENDLOOP.
ENDLOOP.


7 comments:

prakashlu said...

This logic is simply superb Alionzo. I used read in loop but getting index and reading nested loop is really good. Thanks for this too...

arif said...

Is it possible for more than one column / field ?


Tanks

seventyros said...

For a Excellent Online Resource for SAP EP and SAP Web Dynpro ABAP, Visit Learn SAP Online

Abap Community Forums said...

You can learn more about abap at
Abap Community Forums

google said...

Excellent Online Resource for SAP EP and SAP Web Dynpro ABAP. Visit Learn SAP Online for Free

How to make WDJ Component available on SAP EP
SAP Enterprise Portal Application in NWDS
SAP and Their Produstcs - SMB Customer - SAP Business One
What is SAP ?
Architecture of SAP Business One Application
Navigation in SAP Business One
SMB Portal and its Functionality
Netweaver Administrator Day to Day Work
SAP Business Intelligence
Business Partners in SAP Business One
Continuous Stock System in SAP business one

And Many Morte Topics

David E. Jacobs said...

I appreciate your idea here. Definitely ithttp://www.promptessay.com/ has a good content. Thank you for imparting more of your own thoughts. Good job!

ivan koki said...

Really structured and useful information.www.trustwebsitehostingreviews.com/
And everything is clear, thanks. I looked through some posts and must say, they are very interesting. Best regards, essay writer.