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 do you handle in Call Transaction?
what is the transaction code to create LOGO in sap scripts?
Hi, How to call transaction( Any transaction ex:xk03)from ALV Report. Where should I write code?
Explain GET PERNR concept when we use logical data base
What are the methods of interfacing to SAP
How many tables are there in sap?
what is a TEXT Table ?
1 Answers vCentric Technologies,
differnce between screen exit, field exit and function exit
Explain what is the purpose of sap script?
i want to use standard script and driven program.how can i modify standard driven program?in real time how can we execute the standard script?can any one tell me the procedure plz?
SAP query how to use end users?
In delivery processing which step comes first picking, packing, posting goods issue ?