二分法查询(BINARY SEARCH)

以下阐述什么是二分法查询
Binary Search in ABAP is an important topic in terms of interview question. In general, ABAP provides keyword “SEARCH” for searching purpose and that is widely used everywhere. In this article, we will learn: What is a Binary Search and how to implement it in our ABAP programs.

What is a Binary Search?

A Binary Search is a search method in which a particular value is searched from an array (in case of ABAP, Internal Table) of values via a procedure as listed below:

The whole array is firstly sorted.
Then the searched value is compared with the middle value.
If it is equal, then output is shown with index/position of value.
If it is less than the middle value, then values after middle value is discarded and if it is greater than the middle value then the values before middle value is discarded.
Repeat step 4 till we achieve step 3. If it is not achieved till end then “Not Found” message is printed on the screen. The process is shown below using image (click on the image) and program

以下是二分法查询,二分法查询的例子

READ TABLE it_block INTO s_block
                        WITH KEY bukrs = s_rkwa-bukrs
                                 lifnr = s_rkwa-lifnr
                                 bwaer = s_rkwa-bwaer
                        BINARY SEARCH.

猜你喜欢

转载自blog.csdn.net/beyond911/article/details/114842074