We can use SAP ABAP Binary search or linear search to read internal table. Binary search is the faster and more efficient way of accessing large amount of data from internal table instead of linear search.
In linear search, we need more time, because it searches one by one record. If you have less amount of data in internal table, then it’s better to go for linear search. Performance of the linear search improves if desired record is found at beginning of the data. The linear search is not effective when desired record is at the bottom of internal table.
You can use Binary Search in the read statement. Before use of binary search, the table must be sorted by specified keys. Otherwise binary search will not find the correct record. You can use KEY with binary search in read statement because the key points to the exact record in internal table. Binary search divides the list in two equal parts. If the value to be searched is less than the middle value, then search continues in lower part. Again, it divides the list in two equal parts and starts the same processing.
For example, if we have 100 records in internal table and you want search 29th record from internal table. Binary search divides the list in two equal parts. If desired value less than middle value then it avoids the upper part and it searches in lower part. Again, it divides the lower part list into another two parts. This process stops when 29th record is found.
Please send us your questions, comments or assistance, and our team would be glad to assist you.
By Sreedhar Babu (on behalf of SAP Consulting Team)
Apprisia
SAP :: Streamlined
We offer variety of services including SAP ECC ,SAP HR,SAP BW,SAP CRM, SAP SCM,SAP BPM, Business Objects, SAP ABAP Development, SAP BASIS and SAP NetWeaver consulting. We have expertise in providing implementation,development, SAP Migration and SAP support services to SAP customers across diverse industries at a global level.
Have a question on SAP? Write to our SAP Architect : AskTheArchitect@Apprisia.com
(We promise a no-obligation consulting reply)