ABAP 删除内表重复数据

内表要进行排序 然后删除重复行

SORT <内表> BY <字段> [ascending/descending].

DELETE ADJACENT DUPLICATES FROM <内表> COMPARING ALL FIELDS.




*&---------------------------------------------------------------------*
*&      Form  FM_BUTTON_PRT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM FM_BUTTON_PRT.
  LOOP AT IT_DATA INTO WA_DATA.
    IF WA_DATA-SEL = 'X'.
      WA_SELS-PUR_NUM  = WA_DATA-PUR_NUM.
      WA_SELS-CRT_DATE = WA_DATA-CRT_DATE.
      WA_SELS-VEND_NUM = WA_DATA-VEND_NUM.
      WA_SELS-PAY_KEY  = WA_DATA-PAY_KEY .
      WA_SELS-MAT_NUM  = WA_DATA-MAT_NUM .
      WA_SELS-PUR_TXT  = WA_DATA-PUR_TXT .
      WA_SELS-PLT_NUM  = WA_DATA-PLT_NUM .
      WA_SELS-STOR_LOC = WA_DATA-STOR_LOC.
      APPEND WA_SELS TO IT_SELS.
    ENDIF.
  ENDLOOP.
  LOOP AT IT_DATA INTO WA_DATA.
    IF WA_DATA-SEL = 'X'.
      WA_PURNM-PURNM   = WA_DATA-PUR_NUM.
      APPEND WA_PURNM TO IT_PURNM.
      SORT IT_PURNM BY PURNM ASCENDING.
      DELETE ADJACENT DUPLICATES FROM IT_PURNM COMPARING ALL FIELDS.
    ENDIF.
  ENDLOOP.
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      FORMNAME           = 'ZXLI_TEST_002'
    IMPORTING
      FM_NAME            = L_FM_NAME
    EXCEPTIONS
      NO_FORM            = 1
      NO_FUNCTION_MODULE = 2
      OTHERS             = 3.
  CALL FUNCTION L_FM_NAME
    TABLES
      IT_DATA  = IT_SELS
      IT_PURNM = IT_PURNM.
  CLEAR IT_SELS[].

ENDFORM.                    "FM_BUTTON_PRT

你可能感兴趣的:(abap)