一、单行增加
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
WITH NON-UNIQUE KEY land name age weight.
data jtab like sorted table of line.
line-land = 'G'. line-name = 'Hans'.
line-age = 20. line-weight = '80.00'.
INSERT line INTO TABLE itab. "增加记录
或者: Append line to table itab."增加记录
二者区别:
INSERT语句中增加了TABLE关键字,对于不同类型的内表,其意义和用法是有区别的:
1.对于标准表而言,和APPEND LINE TO ITAB。的结果一样。
2.对于排序表而言,插入行不可以打乱关键字的排序顺序,否则报错。
3.对于哈希表而言,插入过程中系统按照关键字对行进行定位。
二、多行增加
INSERT LINES OF itab INTO TABLE jtab.
三、单行统计增加
line-col1 = 'abc'. line-col2 = '12'. line-col3 = 3.
COLLECT line INTO itab.
line-col1 = 'def'. line-col2 = '34'. line-col3 = 5.
COLLECT line INTO itab.
line-col1 = 'abc'. line-col2 = '12'. line-col3 = 7.
COLLECT line INTO itab.
注意:此时itab必须有key。COLLECT根据key相同对其他数据进行累加
一、单行删除
DELETE TABLE itab WITH TABLE KEY col1 = 3.(itab必须有key,因为删除出问题很大,不能随便删除一行)
二、条件多行删除
DELETE itab WHERE ( col2 > 1 ) AND ( col1 < 4 ).
三、删除重复行
DELETE ADJACENT DUPLICATES FROM itab COMPARING ALL FIELDS.
一、单行修改
line-col1 = 2.
line-col2 = 100.
MODIFY TABLE itab FROM line.(只能修改一行,如果没指定key,则第一行进行了修改)
如果不指定key,也可以:
Modify itab index 1.
二、多行修改
DATA itab LIKE HASHED TABLE OF line WITH UNIQUE KEY col1.
DO 4 TIMES.
line-col1 = sy-index.
line-col2 = sy-index ** 2.
INSERT line INTO TABLE itab.
ENDDO.
line-col2 = 100.
MODIFY itab from line transporting col2(必须指定传哪个字段值,否则报错)
WHERE ( col2 > 1 ) AND ( col1 < 4 ).
一、单行查找
DATA: BEGIN OF line,
col1 TYPE i,
col2 TYPE i,
col3 type i,
END OF line.
DATA itab LIKE HASHED TABLE OF line WITH UNIQUE KEY col1.
DO 4 TIMES.
line-col1 = sy-index.
line-col2 = sy-index ** 2.
line-col3 = line-col1 * line-col2.
INSERT line INTO TABLE itab.
ENDDO.
line-col1 = 2.
line-col2 = 3.
line-col3 = 4.
READ TABLE itab FROM line INTO line.(如果不指定key,则读取第一行)
二、单行查找(查找到后指定传递值的字段)
DATA: BEGIN OF line,
col1 TYPE i,
col2 TYPE i,
END OF line.
DATA itab LIKE SORTED TABLE OF line WITH UNIQUE KEY col1.
DO 4 TIMES.
line-col1 = sy-index.
line-col2 = sy-index ** 2.
INSERT line INTO TABLE itab.
ENDDO.
CLEAR line.
READ TABLE itab WITH TABLE KEY col1 = 3
INTO line TRANSPORTING col2. (指定只传递col2的值,不传递col1)