Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

what is a binary search ? and how it is useful in a sorted
internal table ?

Answer Posted / shweta upadhyay

Definition: Search a sorted array by repeatedly dividing
the search interval in half. Begin with an interval
covering the whole array. If the value of the search key is
less than the item in the middle of the interval, narrow
the interval to the lower half. Otherwise narrow it to the
upper half. Repeatedly check until the value is found or
the interval is empty.

SYNTAX : READ TABLE <itab> WITH KEY <k1> = <f1>... <kn> =
<fn> <result>

BINARY SEARCH.

CODE :
REPORT demo_int_tables_read_index_bin.

DATA: BEGIN OF line,
col1 TYPE i,
col2 TYPE i,
END OF line.

DATA itab LIKE STANDARD TABLE OF line.

DO 4 TIMES.
line-col1 = sy-index.
line-col2 = sy-index ** 2.
APPEND line TO itab.
ENDDO.

SORT itab BY col2.

READ TABLE itab WITH KEY col2 = 16 INTO line BINARY SEARCH.

WRITE: 'SY-SUBRC =', sy-subrc.

The output is:

SY-SUBRC = 0

The program fills a standard table with a list of square
numbers and sorts them into ascending order by field COL2.
The READ statement uses a binary search to look for and
find the line in the table where COL2 has the value 16.

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

in bdc session method. if u run the record in fore ground manually i have a 7 records but at the time of record processing first record produces the error how can u process records manually in fore ground please tell me any one knows?

2135


Explain sap abap 3-tier architecture?

1238


How can I get ascii value of any letter? Is there any function?

1200


What actually happens in real-time recruitment? : sap abap hr

1029


In which time constraint does the infotype records depend on the subtype ? : abap hr

1072


What is page window?

959


Explain the differences between at selection-screen and at selection-screen output?

1023


What are table clusters?

1009


What is modularization and its benefits? : abap modularization

1170


What happens if a function module runs in an update task? : abap modularization

1035


Difference between Read and Get cursor?

2051


what is the process of creating quotation using BAPIs.

2038


What is evaluation path, where do we do it and why? : sap abap hr

1157


What are the prerequisites for creating foreign key relationship?

1140


Mention what is alv programming in abap?

1179