Binary Search Example On An Internal Table

Binary search on an internal table which has both ascending and descending order sorted fields.
 
DATA(rnd) = cl_abap_random_int=>create( seed = + sy-uzeit
min = 1
max = 100 ).
 
DATA:
 
BEGIN OF line,
a TYPE i,
b TYPE i,
c TYPE i,
d TYPE i,
END OF line,
 
itab LIKE TABLE OF line WITH EMPTY KEY.
 
DO 10000 TIMES.
 
itab = VALUE #( BASE itab
( a = rnd->get_next( )
b = rnd->get_next( )
c = rnd->get_next( )
d = rnd->get_next( ) )
).
 
ENDDO.
 
SORT itab BY a b ASCENDING c d DESCENDING.
 
READ TABLE itab INTO DATA(wa) WITH KEY a = 10 b = 10 BINARY SEARCH.
 
BREAK-POINT.

ABAP Tips

See Also
Techniques of List Processing and SAP Query

Get help for your ABAP problems
Do you have a ABAP Question?

ABAP Books
ABAP Certification, BAPI, Java, Web Programming, Smart Forms, Sapscripts Reference Books

More ABAP Tips

Main Index
SAP ERP Modules, Basis, ABAP and Other IMG Stuff

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.