技术开发 频道

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

*----------------------------------------------------------------------*
*                                                           方法二
*----------------------------------------------------------------------*

  Z_TEST5 .

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

"定义一个具有列结构的内表

DATA: BEGIN OF IT_TABLE OCCURS 10,
      f1(1)     TYPE  C,
      f2(5)     TYPE  C,
      f3(12)    TYPE  C,
      f4(10)    TYPE  C,
      f5(12)    TYPE  C,
    END OF IT_TABLE.

"定义一个和该内表含有相同结构的内表

DATA IT_TEST LIKE IT_TABLE.

"定义一个和该内表含有相同结构的字段符号

FIELD-SYMBOLS <FS> LIKE IT_TABLE.

"向内表中放入数据

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

"向内表中放入数据

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

"向内表中放入数据

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

"向内表中放入数据

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

"向内表中放入数据

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

"对内表按照f1,f2,f3三列进行排序

SORT IT_TABLE BY f1 f2 f3.

"把内表列付给字段符号,这样字段符号,就指向了内表的那一列的值

LOOP AT IT_TABLE ASSIGNING <FS> .

"这句话的意思我不是很懂,大家有清楚的告诉我下。是一个值还是一列还是整个表?
    IT_TABLE = <FS>.

"比较IT_TEST内表中的f1字段的值与<fs>指向的f1的值是不是相同
 IF IT_TEST-F1 = <FS>-F1 .

"相同的话清空
    CLEAR <FS>-F1.
    IF IT_TEST-F2 = <FS>-F2.
    CLEAR <FS>-F2.
       IF IT_TEST-F3 = <FS>-F3.
         CLEAR <FS>-F3.
       ENDIF.
    ENDIF.


 ENDIF.
   IT_TEST = IT_TABLE.
ENDLOOP.

"显示到屏幕

LOOP AT IT_TABLE.
  WRITE : / IT_TABLE-F1,IT_TABLE-F2,IT_TABLE-F3,IT_TABLE-F4.
ENDLOOP.

0
相关文章