通过例子学习ABAP(四)--INSERT语句对于三种类型的内表不同效果

(1)  通过索引插入行: INSERT LINE INTO ITAB INDEX IDX.

(2)一般性的插入单行:INSERT [LINE INTO | INITIAL LINE INTO ] TABLE ITAB.

语句中增加了TABLE关键字,对于不同类型的内表,其意义和用法是有区别的:
1.对于标准表而言,和APPEND LINE TO ITAB。的结果一样。

2.对于排序表而言,插入行不可以打乱关键字的排序顺序,否则报错。

3.对于哈希表而言,插入过程中系统按照关键字对行进行定位。

例如:

REPORT demo_int_tables_insert .

DATA: BEGIN OF line,
        land(3)  TYPE c,
        name(10) TYPE c,
        age      TYPE i,
        weight   TYPE p DECIMALS 2,
      END OF line.

DATA itab LIKE SORTED TABLE OF line            “替换成 STANDARD 和HASHED ,看看有什么不同。
          WITH NON-UNIQUE KEY land name age weight.

line-land = 'G'.   line-name   = 'Hans'.
line-age  = 20.    line-weight = '80.00'.
INSERT line INTO TABLE itab.

line-land = 'USA'. line-name   = 'Nancy'.
line-age  = 35.    line-weight = '45.00'.
INSERT line INTO TABLE itab.

line-land = 'USA'. line-name   = 'Howard'.
line-age  = 40.    line-weight = '95.00'.
INSERT line INTO TABLE itab.

line-land = 'GB'.  line-name   = 'Jenny'.
line-age  = 18.    line-weight = '50.00'.
INSERT line INTO TABLE itab.

line-land = 'F'.   line-name   = 'Michele'.
line-age  = 30.    line-weight = '60.00'.
INSERT line INTO TABLE itab.

line-land = 'G'.   line-name   = 'Karl'.
line-age  = 60.    line-weight = '75.00'.
INSERT line INTO TABLE itab.

LOOP AT itab INTO line.
  WRITE: / line-land, line-name, line-age, line-weight.
ENDLOOP.

posted @ 2008-10-31 11:38  elegant  阅读(1403)  评论(0编辑  收藏  举报