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

Abap Community Forums said...

You can learn more about abap at
Abap Community Forums

Unknown 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!

Unknown 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.

oracleR12 said...

Hi,
Looking forward to learn something more from your blog, It is a nice article which is informative and useful.
Thank you.
oracle R12 training

Unknown said...


The blogger has shared such an interesting gallery with the readers. I believe that the people who have read the details alongside this gallery have been enlightened and will be able to improve on physical education. When I saw the title for this article, I knew that it is meant for educational purposes and that why I also chose to inform the readers on HOW TO OBTAIN AN EXCELLENT UNIVERSITY ENTRY ESSAY.