what is a binary search ? and how it is useful in a sorted
internal table ?
Answer / 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 |
how many main windows you can maintain in a smartform? wt is the types of window in smartform?
What are the personnel administration related Infotypes
What are reference fields in data dictionary ? how do u assign them to a table field?
Program lines for the radio button selection and unabling some input variables in section screen
I Developed Interactive report to display Customers, Sales Details and Delivery Priority? Why did u create these reports?what was the buisness requirements? what wer the inputs At Selection Screen?what was the output?how was the desighn of the screen?
how bapi is different from call transaction/session?
What are the difference between tables and structures?
what is the differenc between table control and table control wizard?
Why don’t use LSMW method instead of BDC methods, if the data is master data?
What are indexes? : abap hr
what are the diff types of dispatcher in sap ?
What is WEB Dynpro Comp. / intf?