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

binary search

Former Member
0 Likes
747

hi

how binary search is performed?

regards

ratna

1 ACCEPTED SOLUTION
Read only

gopi_narendra
Active Contributor
0 Likes
686

read table itab into wa_itab with key <> binary search.

Binary Search is based on the below principle

suppose if u have

1

2

3

4

5

6

7

8

9

10

now u want to find 3. so now it splits 1 to 10 into 2 halves, now 3 is in the first half

1

2

3

4

5

so it searches only in the first half, it does not search in the remaining values

Hope this is clear

Regards

- Gopi

6 REPLIES 6
Read only

gopi_narendra
Active Contributor
0 Likes
687

read table itab into wa_itab with key <> binary search.

Binary Search is based on the below principle

suppose if u have

1

2

3

4

5

6

7

8

9

10

now u want to find 3. so now it splits 1 to 10 into 2 halves, now 3 is in the first half

1

2

3

4

5

so it searches only in the first half, it does not search in the remaining values

Hope this is clear

Regards

- Gopi

Read only

Former Member
0 Likes
686

it is used for internal tables...When u loop one internal table and want to read second internal table, u use READ table .........with binary search.

This means if there are 100 records, it will split into 50 records and search only these 50 for mapping....

using Binary search is a fast & reliable method.

Read only

Former Member
0 Likes
686

Hi Ratna,

When ever there are some records like

1

2

3

4

5

6

7

8

9.

First the table should be sorted.

Suppose u r searching for 8 the record. The First the System Divides if into two Divisions. at the center means at 5. Then it will seach the records is greater than 5 or less than. Since is greater than 5 then it comes Then it come to the second half. Then again It Divides and Find the Record. Due to Which SEarch will be faster than others.

Remember when ever u r performing binary search the table has to be sorted.

Bye

Murthy

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
686

Hi,

Binary searhc is useful on a sorted internal table.

If it is a standard table then sort it before you force binary search by adding the keyword BINARY SEARCH to read.

If it is SORTED Table then it will be searched using the binary search.

Its like you decide the area you need to search.

Say you have 10 entries on the first go you will decide the 5 entries that needs to be searched,

then In the 5 entries you decide the next half to be searched.

This way you will search till there is one element left which is nothing but the one you are looking for.

Its not the you devide the list into two halfs with same number of elements.

Binary means two so you devide the entire list into two and decide the area to be searched and again proceed with that area with the same logic.

Regards,

Sesh

Message was edited by:

Seshatalpasai Madala

Read only

Former Member
0 Likes
686

When a programmer uses the 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.

<b>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.</b>

Instead of Read table int_fligh with key airln = ‘LF’, this should be used Read table int_fligh with key airln = ‘LF’ binary search.

I hope this helps.

Best Regards,

Vibha

*Please mark all the helpful answers

Read only

Former Member
0 Likes
686

Hi,

one pre-requisite for binary search is that table has to be sorted in ascending order,

E.g.

say Itab[] has 5 entries.

10

20

30

40

50,

Now say you want to serach value 20.

Binary serach divides the sorted internal table into 2 halves 5/2 gives

1) 10

20

30

2) 40

50

Now it compares the value to be searched(i.e. 10) with last entry of the first half

if search value is less than last entry of first half it again performs this division on first half of the table.

else compares search value with first entry of 2nd half search value is greater or equal to first entry of second half it dividies the second half till the seasrch value is found.

Note: you cannot do binary search on tables sorted in descending order.

Regards,

Raghavendra