1. 程式人生 > >ABAP 三種內表的區別

ABAP 三種內表的區別

ABAP中有三類內表,標準表,排序表和雜湊表。

三種內表介紹

   標準表的每一行對應一個邏輯索引-SY-TABIX,填充內表的時候,可以將資料附加在現有行

之後,也可以插入到指定的位置,程式對內錶行的定址操作可通過關鍵字或索引進行。在對錶

進行插入刪除等操作時,各資料行在記憶體中的位置不變,系統僅重新排列各資料行的索引值。

   排序表也有邏輯索引,不同的是排序表總是按其表關鍵字升序排列後再進行儲存,也就是在

記憶體中的位置發生改變。

   雜湊表沒有索引,只有關鍵字。

行訪問方式

                    標準表                    排序表                 雜湊表

索引訪問             允許                       允許                 不允許

關鍵字訪問           允許                       允許                  允許

相同值關鍵字行       可重複                   可重複或不可重複       不可重複

推薦訪問方式       主要通過索引               主要通過關鍵字        只能通過關鍵字 

具體到使用什麼型別的內表    

    對於一個小於100行的內表,且很少使用關鍵字操作,則使用標準表沒有效率問題;資料量

比較巨大,切不存在重複行,只需使用關鍵字訪問的內表應定義為雜湊表;排序表適用於執行

期內必須以某種排序形式出現的內表。

1.Standard Internal Tables: These tables have a linear index
and can be accessed using the index or the key. The response
time is in linear relationship with number of table entries.
These tables are useful when user wants to address
individual table entries using the index.
2.Sorted Internal Tables: These tables also have an index
and the key. But, the response time is in logarithmic
relationship with number of table entries, since it uses
binary search algorithm instead of linear search. These
tables are useful when user wants the table to be sorted
while additional entries have to be added.
3.Hashed Internal Tables: These tables have no index, but
have the key. The response time is constant irrespective of
number of table entries, since it uses a Hash algorithm.
These tables are useful when user wants to access the
entries with key only.