standard table,sorted table可以通过索引和关键字进行访问,hashed table只能通过关键字进行访问
standard table在增加或插入数据行时并不对数据行的特理地址进行重新排序存储,只是对其索引进行重表排列。sorted table在增加和插入数据行时要对数据存储的物理地址进行重新排列。
hashed table在检索数据里与数据行数无关,时间复杂度通常是o(1)的时间
SAP里内表的层次结构如下:
any table
index tablehashed table
standard table sorted table
any table和index table是抽象接口类型,不能用于定义具体的数据对象
举例: DATA: BEGIN OF line, num TYPE i, sqr TYPE i, END OF line, itab LIKE STANDARD TABLE OF line WITH KEY table_line. DO 5 TIMES. line-num = sy-index. line-sqr = sy-index ** 2. APPEND line TO itab. ENDDO. LOOP AT itab INTO line. WRITE: / line-num,line-sqr. ENDLOOP. 注:特别要注意的定义内表的使用的关键字LIKE。通过对象来定义内表要使用关键字LIKE。在黄佳的书上是有误的。
在声明内表关键字时TABLE LINE已经废弃不用,而是使用TABLE_LINE代替。TABLE_LINE表示使用内表行作为表关键字。例如: In ABAP Objects, the following statement causes an error message:
... TABLE LINE ...
Correct syntax:
... table_line ...
Cause:
The pseudo-component table_line replaces the TABLE LINE constuction.
在定义内表时使用WITH HEADER LINE选项表示定义内表时也定义同名的工作内。如果在使用的过程中不能明确的分辩出是使用内表或是工作区,那么在名称之后加"[]"表示明确的使用内表。如下: TYPES: BEGIN OF address, street(20) TYPE c, city(20) TYPE c, END OF address. DATA: BEGIN OF company, name(20) TYPE c, addresses TYPE address, END OF company. DATA: itab_company LIKE STANDARD TABLE OF company WITH NON-UNIQUE KEY name. DATA: wa LIKE company. wa-name = 'china'. wa-addresses-street = 'aaa'. wa-addresses-city = 'shanghai'. APPEND wa TO itab_company. LOOP AT itab_company INTO wa. WRITE: / sy-tabix,wa-name,wa-addresses-street,wa-addresses-city. ENDLOOP. wa-name = 'america'. wa-addresses-street = 'ccc'. wa-addresses-city = 'new york'. INSERT wa INTO itab_company INDEX 1. LOOP AT itab_company INTO wa . WRITE: / sy-tabix,wa-name,wa-addresses-street,wa-addresses-city. ENDLOOP. wa-name = 'america'. wa-addresses-street = 'DDD'. wa-addresses-city = 'new york'. MODIFY itab_company[] INDEX 1 FROM wa. WRITE: / '...............................'. LOOP AT itab_company INTO wa . WRITE: / sy-tabix,wa-name,wa-addresses-street,wa-addresses-city. ENDLOOP.