二分法查询(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.

Summary
Before you use it ,you should sort the internal table as a filed.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值