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

what are the 2 other types of views, which are not allowed in release 3.0? : abap data dictionary

618


Can we include customizing include or an append structure with pooled or cluster tables?

670


What is the difference between tables and structures?

626


How can we achieve MVC ?

908


How we format the data before writing a statement in the report?

514






What is database view ? : sap abap data dictionary

604


1. what is IDOC monitoring ? what is the tcode used for idoc monitoring ? 2 . what is change pointer in ale ?

6657


What is a type group?

550


List the various components of the enterprise structure in systems, applications, and products (sap) in human capital management (him)? : sap abap hr

523


What are the steps to execute session method?

604


On abap: did you set up a workflow? Are you familiar with all the steps for setting up a workflow?

582


Why bapi need then bdc ? : abap bdc

582


Explain the different types of data dictionary objects?

528


What is an on”*-input filed” statement?

605


How the transaction that are programmed by the user can be protected?

645