Sorting an already sorted internal table in ABAP

ABAPSAP

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.

raja
Published on 19-Dec-2017 11:01:52
Advertisements