标准表和哈希表 Abap 的区别
您能否给我一个关于使用“标准表”、“哈希表”或简单的“表”之间的区别的清晰解释。另外“初始大小0”是什么意思?
作为参考,请查看下面的代码。
it_c01_d006_raw TYPE STANDARD TABLE OF /bic/ac01_d00600
INITIAL SIZE 0,
it_c01_d006 TYPE HASHED TABLE OF /bic/ac01_d00600
WITH UNIQUE KEY /bic/cemployee /bic/cdatetype,
it_c01_d002 TYPE TABLE OF /bic/ac01_d00200.
Can you please give me a clear explanation on the difference between using "standard table of", "Hashed table of", or simply "table of". Also what is the meaning of "initial size 0"?
For reference please have a look in to below code..
it_c01_d006_raw TYPE STANDARD TABLE OF /bic/ac01_d00600
INITIAL SIZE 0,
it_c01_d006 TYPE HASHED TABLE OF /bic/ac01_d00600
WITH UNIQUE KEY /bic/cemployee /bic/cdatetype,
it_c01_d002 TYPE TABLE OF /bic/ac01_d00200.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TYPE STANDARD TABLE OF
和TYPE TABLE OF
的含义完全相同,如果没有指定其他内容,则隐含STANDARD
。然而,在面向对象的上下文中,您现在需要完整地声明内部表,并且您将无法省略STANDARD
添加。在这种情况下,它只是一个标准的内部表,可以通过读取每个表索引来访问,或者如果您已手动对表进行排序,则可以通过键来访问。TYPE HASHED TABLE 的表创建一个使用内部 HASH 算法表示的内部表,允许读取该表,其中成本(近似)与表的大小无关。当您有大量读取但写入相对较少的大型数据集时,使用这种类型的表是很好的选择。声明哈希表时,您还必须声明一个
UNIQUE KEY
,因为哈希算法依赖于此。INITIAL SIZE 0
也是代码的冗余使用 - 它意味着内存分配将发生在集合块中。 (我不确定这个大小是否是预定义的,或者是由 BASIS 配置的),但 INITIAL SIZE 0 是默认值。如果您希望内存分配发生在内部表行数 10 倍的集合中,则可以使用“初始大小 10”,但在大多数情况下,保留默认内存分配比尝试强制分配要好。此外
TYPE SORTED TABLE
的表可以使用UNIQUE
或NON-UNIQUE
键声明。读取记录的成本低于STANDARD
表,因为它允许BINARY SEARCH
,但高于HASHED
桌子。写入成本比STANDARD
表稍贵,但低于HASHED
表。The meaning of
TYPE STANDARD TABLE OF
andTYPE TABLE OF
is exactly the same,STANDARD
is implied if nothing else is specified. However, in the OO-context you are now expected to declare internal tables fully and you would not be able to leave out theSTANDARD
addition. In this case it is just a stock-standard internal table that can be accessed by reading per the table index, or by key if you have sorted the table manually.A table of
TYPE HASHED TABLE
creates an internal table that is represented using an internal HASH algorithm, allowing reads to the table where the cost is (by approximation) independent from the size of the table. Using this type of table is good when you have large data-sets with a lot of reads, but comparatively few writes. When declaring a hash table you have to also declare aUNIQUE KEY
, as the HASH algorithm is dependent on this.INITIAL SIZE 0
is also a redundant use of code - it means that memory allocation will occur in set blocks. (I'm not sure if this size is predefined, or configurable by BASIS), but INITIAL SIZE 0 is the default. If you wanted memory allocation to happen in sets of 10 times the number of lines in your internal table, you would have used 'INITIAL SIZE 10', but in most cases leaving the default memory allocation is better than trying to force it.In addition
A table of
TYPE SORTED TABLE
can be declared with either anUNIQUE
or aNON-UNIQUE
key. The cost to read a record is less than that of aSTANDARD
table, as it allows aBINARY SEARCH
, but more than that of aHASHED
table. The cost to write is slightly more expensive than aSTANDARD
table, but less than that of aHASHED
table.标准表
如果您要使用索引来处理各个表条目,这是最合适的类型。索引访问是最快的访问。您应该通过附加行(ABAP APPEND 语句)来填充标准表,并通过指定索引(相关 ABAP 命令的 INDEX 选项)来读取、修改和删除条目。标准表的访问时间与表条目数呈线性关系增加。如果您需要密钥访问,并且可以在单独的步骤中填充和处理表,那么标准表特别有用。例如,您可以通过附加条目来填充表格,然后对其进行排序。如果您使用带有键访问的二分搜索选项,则响应时间与表条目数成对数比例。
哈希表
对于主要操作是键访问的任何表来说,这是最合适的类型。您无法使用哈希表的索引来访问该表。无论表条目数有多少,键访问的响应时间都保持不变。与数据库表一样,哈希表始终具有唯一的键。如果您想要构建和使用类似于数据库表的内部表或用于处理大量数据,则哈希表非常有用。manu
Standard table
This is the most appropriate type if you are going to address the individual table entries using the index. Index access is the quickest possible access. You should fill a standard table by appending lines (ABAP APPEND statement), and read, modify and delete entries by specifying the index (INDEX option with the relevant ABAP command). The access time for a standard table increases in a linear relationship with the number of table entries. If you need key access, standard tables are particularly useful if you can fill and process the table in separate steps. For example, you could fill the table by appending entries, and then sort it. If you use the binary search option with key access, the response time is logarithmically proportional to the number of table entries.
Hashed tables
This is the most appropriate type for any table where the main operation is key access. You cannot access a hashed table using its index. The response time for key access remains constant, regardless of the number of table entries. Like database tables, hashed tables always have a unique key. Hashed tables are useful if you want to construct and use an internal table which resembles a database table or for processing large amounts of data.manu