Sorting an already sorted internal table in ABAP


If you leave 2nd sort, it would be quicker as itab will be there in right order.

SORT itab by f1 f2 f3.
READ TABLE itab WITH KEY f1 = 'A'
   f2 = 'B'
   f3 = 'C' BINARY SEARCH.
READ TABLE itab WITH KEY f1 = 'A' BINARY SEARCH.

When 2nd READ TABLE is by f2, you should leave the SORT and BINARY SEARCH as well. In best case scenario, SORT + BINARY SEARCH speed is n+log(n).

Also note that worst case of sort is n log n.

Updated on: 14-Feb-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements