默认情况下如何对内部表进行排序?
因此,我想知道当我声明时是否
lt_table TYPE STANDARD TABLE OF mara.
?
lt_table TYPE STANDARD TABLE OF mara WITH DEFAULT KEY.
与不声明默认键相同的标准表键是否相同
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一样的,如:
a 默认键(下面的第一个项目符号)或什么都没有(第二个):
编辑2022年5月31日:关于“标准表键”的含义可能会有一些混乱。这可能会使人们认为桌子已经排序,然后访问更快。
那是错误的。
仅当您按Comp1 comp2 对ITAB进行明确对ITAB进行明确排序(在耗时之时),然后使用
使用键Comp1 = ... comp2 =。 ..二进制搜索
。声明标准表的主键(默认键或明确组件)是一种不提及
sort> sort
,读取表
等之后的组件的方法,而是ABAP文档建议在sort
,读取表
等之后明确声明它们。因此,我对声明标准表的主要键没有任何兴趣。
nb:
收集
仅基于标准表的主要键,因此别无选择,除非您将收集
用这样的代码替换为:如果要:如果要使用排序的表进行更快的访问,更喜欢使用
键入表格表
或键入hashed表
(或任何替代语法都具有辅助键),它将真正对表和访问更快,编译器将使用sort
(错误,因为已经排序),读取表
等来发送更好的警告或错误消息,而不是标准表(仅在使用ATC时才警告)。有关更多信息,请参见
That's the same, as explained in the ABAP documentation:
A standard key is when you indicate
DEFAULT KEY
(first bullet point below) or nothing (second one):EDIT May 31st, 2022: there can be some confusion about the meaning of the "keys of a standard table". That could make people think that the table is sorted and the access is then faster.
That's wrong.
It will be faster only if you sort explicitly your internal table
SORT itab BY comp1 comp2
(once as it's time consuming), and useREAD TABLE itab WITH KEY comp1 = ... comp2 = ... BINARY SEARCH
.Declaring the primary key (default key or explicit components) of a standard table is a way to not mention the components after
SORT
,READ TABLE
, etc., but the ABAP documentation recommends to explicitly declare them afterSORT
,READ TABLE
, etc.Consequently, I don't see any interest in declaring the primary key of a standard table.
NB:
COLLECT
works only based on the primary key of the standard table, so here there's no choice except if you replaceCOLLECT
with code like this for instance:If you want to use a sorted table for faster access, prefer declaring the table with
TYPE SORTED TABLE
orTYPE HASHED TABLE
(or any alternate syntax to have Secondary Keys), it will really sort the table and accesses are faster, the compiler will send better warning or error messages withSORT
(error because already sorted),READ TABLE
, etc., than for a standard table (only some warnings if you use ATC).For more information, see ABAP documentation - itab - Selection of the Table Category