技术开发 频道

ABAP实例:内表重复字段如何删除

*----------------------------------------------------------------------*
* 变量定义
*----------------------------------------------------------------------*

DATA:
  STR_CLASS   TYPE  T_STR_CLASS,
  IT_TABLE    TYPE  T_IT_TABLE.

*----------------------------------------------------------------------*
* 主处理
*----------------------------------------------------------------------*

"内表中写入数据

STR_CLASS-f1 = 'a'.
STR_CLASS-f2 = '100'.
STR_CLASS-f3 = '2009-1-1'.
STR_CLASS-f4 = '20'.
STR_CLASS-f5 = '2009-1-1'.
APPEND STR_CLASS TO IT_TABLE.
CLEAR STR_CLASS.

"内表中写入数据

STR_CLASS-f1 = 'a'.
STR_CLASS-f2 = '100'.
STR_CLASS-f3 = '2009-1-1'.
STR_CLASS-f4 = '30'.
STR_CLASS-f5 = '2009-1-3'.
APPEND STR_CLASS TO IT_TABLE.
CLEAR STR_CLASS.

"内表中写入数据

STR_CLASS-f1 = 'a'.
STR_CLASS-f2 = '100'.
STR_CLASS-f3 = '2009-1-1'.
STR_CLASS-f4 = '50'.
STR_CLASS-f5 = '2009-1-4'.
APPEND STR_CLASS TO IT_TABLE.
CLEAR STR_CLASS.

STR_CLASS-f1 = 'a'.
STR_CLASS-f2 = '30'.
STR_CLASS-f3 = '2009-1-12'.
STR_CLASS-f4 = '30'.
STR_CLASS-f5 = '2009-1-14'.
APPEND STR_CLASS TO IT_TABLE.
CLEAR STR_CLASS.

"内表中写入数据

STR_CLASS-f1 = 'b'.
STR_CLASS-f2 = '20'.
STR_CLASS-f3 = '2009-1-3'.
STR_CLASS-f4 = '10'.
STR_CLASS-f5 = '2009-1-22'.
APPEND STR_CLASS TO IT_TABLE.
CLEAR STR_CLASS.

"对内表按照f1,f2,f3这三个字段进行排序

SORT IT_TABLE BY f1 f2 f3.

"输出列头
WRITE: /1 'F1', 5 'F2', 12 'F3', 26 'F4', 38 'F5'.

"遍历内表数据显示
LOOP AT IT_TABLE INTO STR_CLASS.

"对于f1列内容改变时,显示到屏幕,不改变不显示(*AT NEW的用法见最后)

 AT NEW f1.
   WRITE: /1 STR_CLASS-f1.
 ENDAT.

"对于f2列内容改变时,显示到屏幕,不改变不显示

 AT NEW f2.
   WRITE: 5 STR_CLASS-f2.
 ENDAT.

"对于f3列内容改变时,显示到屏幕,不改变不显示

 AT NEW f3.
   WRITE: 12 STR_CLASS-f3.
 ENDAT.

"对于f4,f5列内容显示到屏幕

 WRITE: 26 STR_CLASS-f4, 38 STR_CLASS-f5.

"换新行
 NEW-LINE.

ENDLOOP. 

0
相关文章