Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

reg: one basic thing

Former Member
0 Likes
604

i have one basic doubt,

please clear that.

what is sequential read?

what is binary search? how they differ each other ?

for eg

i have 20 records in a database,

1 ACCEPTED SOLUTION
Read only

dani_mn
Active Contributor
0 Likes
578

hi,

Sequential read is that we start reading records from first and untill we find the required one.

Like in a internal table if you are searching for some specific record then in sequential read it will start searching from the first record untill it finds the required or the records get finished.

Binary Search.

For binary search the internal table should be sorted first. In binary search it divides the records into two halfs and then select one half and again it divides into two halfs untill the value found or records finished.

Like you have 20 records. it divides it into two halfs of 10, 10 and then look for the required value is greater than the first half or not. if it is greater it leaves the first half and start searching in second half.

Thats the reason binary search is fast because it filters half values in one comparison.

Regards,

HRA

5 REPLIES 5
Read only

Laxmana_Appana_
Active Contributor
0 Likes
578

Hi,

Whenever you use read command, the table is sequentially searched. This slows down the processing. Instead of this, use the binary search addition. The binary search algorithm helps faster search of a value in an internal table. It is advisable to sort the internal table before doing a 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.

check these links:

/people/harry.dietz/blog/2005/10/28/performance-improvement-hints-3-internal-table--fill-and-read

http://www.thespot4sap.com/Articles/SAPABAPPerformanceTuning_BinarySearch.asp

Regards

Appana

Read only

dani_mn
Active Contributor
0 Likes
579

hi,

Sequential read is that we start reading records from first and untill we find the required one.

Like in a internal table if you are searching for some specific record then in sequential read it will start searching from the first record untill it finds the required or the records get finished.

Binary Search.

For binary search the internal table should be sorted first. In binary search it divides the records into two halfs and then select one half and again it divides into two halfs untill the value found or records finished.

Like you have 20 records. it divides it into two halfs of 10, 10 and then look for the required value is greater than the first half or not. if it is greater it leaves the first half and start searching in second half.

Thats the reason binary search is fast because it filters half values in one comparison.

Regards,

HRA

Read only

Former Member
0 Likes
578

hello sir,

still i have little bit doubt in your answer,

eg)

we have 20 records.

suppose we want to read the record 15 th means.

in sequential read it start from 1 to 14 and read 15 th.

likewise in binary search.

it split 20 into 10 10.

it start reading first 10 and then next 10. in the next 10 it read the 5th record.

from these both method we want to wait upto 15 th record?

then how it is fast when comapre with sequential read

Read only

Former Member
0 Likes
578

hi,

Read with binary search is more faster than sequential read. We have to make sure that teh internal table is sorted before using binary search addition. Otherwise, we get incorrect results.

If there is binary search addition, the first half of internal tbale is searched, If it is not found still, then second half of internal table is also searched.

Binary search applies the same concept of BINARY SORT.

Regards,

Sailaja.

Read only

0 Likes
578

Hi,

Sequential read is like reading the record one by one starting from 1st in the table. When the required record is found it shows the search result.

In case of Binary Search the table is divided into two halfs. The middle of each half is treated as the filter criteria called the key. The search element is now searched with the help of this key. Doing this we traverse through half of the table rather than sequentialy going through the records.

The read with binary search is faster and quick as not whole recordas are to be traversed.

Hope this solves your problem..