READ TABLE ..... BINARY SEARCH问题

Read Table 的语法很多,这里说一种特殊情况,Read Table 中查询的时候对标准内表经常有一种二分优化查找,用Binary
search的时候首先必须要有查询条件;但如果查询条件满足的项目不至一条时,这时得到的是这些数据中索引排在最前面的数据;

如: 001   0001   20100101

001   0001  20100103

001   
0001  20100105

READ TABLE itab  INTO  wa  WITH KEY  col1 = ‘001‘
col2 = ‘0001‘
BINARY SEARCH.


这时得到的是第一条
,001 0001 20100101 而不是 001 0001
20100103   
这好像不符合二分法查找逻辑。按结果来看,这里的机制是先去匹配了查询条件,将匹配查询条件的数据全拉出来,然后取第一条,而不是按binary search
正常机制,先将low+high / 2位置的数据与条件匹配,成功就取出来。从结果来看,ABAP的二分机制实际是没用的。

然后做如下测试,先不对数据排序;

如: 001   0001   20100101

001  
0002  20100103

001   
0001  20100105

001   
0003  20100105

001   
0001  20100107

READ TABLE itab  INTO  wa  WITH KEY  col1 = ‘001‘
col2 = ‘0001‘
BINARY SEARCH.

得到的结果是001 
0001  20100101 也是索引最低数据;

所以最好的解释:ABAP的二分查找机制是按位置n/2,n/4、、、再一半、、、直到最后一条数据;在这个过程中得到匹配数据仍然不停止将继续二分查找,不断的用新的匹配数据去匹配旧的数据;因为新的数据索引肯定比旧的索引低;

READ TABLE ..... BINARY SEARCH问题,布布扣,bubuko.com

时间: 2024-10-16 21:31:26

READ TABLE ..... BINARY SEARCH问题的相关文章

关于 使用Binary Search (二分法)遇到的一些问题

READ命令使用顺序查找数据表,这会降低处理速度.取而代之,使用binary search的附加命令,可以使用二分查找算法,可以帮助加快内表查找速度. 在使用binary search之前必须首先将内表排序,否则有可能找不到记录,因为二分查找反复将查找区间对半划分,如果要查找的值小于查找区间的中间位置的数据项值,则查找区间将缩小到前半个区间,否则查找将局限于后半区间.然后.................. 今天工作中写了个REPORT,当我进行Read Table 的时候,并且对象数据存在的情

Binary search tree system and method

A binary search tree is provided for efficiently organizing values for a set of items, even when values are duplicated. In generating the binary search tree, the value of each item in a set of values is determined. If a particular value is unique and

Method for balancing binary search trees

Method for balancing a?binary?search?tree. A computer implemented method for balancing a?binary?search?tree includes locating a node in a?binary?search?tree, determining whether a depth of the located node is greater than a threshold, and performing

【组队赛三】—E Binary Search cf448D

Multiplication Table Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 448D Description Bizon the Champion isn't just charming, he also is very smart. While some of us were learning the multiplica

[LeetCode] Find Mode in Binary Search Tree 找二分搜索数的众数

Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST. Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than or equal to the nod

235. Lowest Common Ancestor of a Binary Search Tree

1. 问题描述 Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes v and w as the lowest node in T th

leetcode 109 Convert Sorted List to Binary Search Tree

题目连接 https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/ Convert Sorted List to Binary Search Tree Description Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. /** * De

Lowest Common Ancestor of a Binary Search Tree

1. Title 235. Lowest Common Ancestor of a Binary Search Tree 2. Http address https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/ 3. The question Given a binary search tree (BST), find the lowest common ancestor (LCA) of two

LeetCode 50 Pow(x, n)(Math、Binary Search)(*)

翻译 实现pow(x, n). 原文 Implement pow(x, n). 分析 首先给大家推荐维基百科: zh.wikipedia.org/wiki/二元搜尋樹 en.wikipedia.org/wiki/Binary_search_tree 其次,大家也可以看看类似的一道题: LeetCode 69 Sqrt(x)(Math.Binary Search)(*) 然而这题我还是没有解出来,看看别人的解法-- class Solution { private: double myPowHel