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
Describe the data classes?
What is the procedure you followed to upload the data?
What are the different types of views in sap? : abap data dictionary
Name a few data dictionary objects?
What are interface/conversion programs in SAP?
What will exactly the hide statement do?
What are the personnel administration related Infotypes
What is the difference between a structure and a table?
any 1 having notes on SAP-ABAP certification, or even if any 1 could provide the url for getting notes on SAP-ABAP certification, would be appreciated.
What is the length of function code at user-command?
How will you insert record in a sorted table
Explain what is the step-by-step process to create a table in data dictionary?
There is a delivery that is being created through the ABAP code and in the middle it says delivery created but someone is modifying , how would you rectify this issue
how to update the filed value in SAP in ZAWSYS and create time and date? please tell me the answer
What are the advantages/ dis-advantages of logical databases?