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
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?
Explain sap abap 3-tier architecture?
How can I get ascii value of any letter? Is there any function?
What actually happens in real-time recruitment? : sap abap hr
In which time constraint does the infotype records depend on the subtype ? : abap hr
What is page window?
Explain the differences between at selection-screen and at selection-screen output?
What are table clusters?
What is modularization and its benefits? : abap modularization
What happens if a function module runs in an update task? : abap modularization
Difference between Read and Get cursor?
what is the process of creating quotation using BAPIs.
What is evaluation path, where do we do it and why? : sap abap hr
What are the prerequisites for creating foreign key relationship?
Mention what is alv programming in abap?