美文网首页
快速删除acctit表中数据

快速删除acctit表中数据

作者: SmalltalkVoice | 来源:发表于2020-12-02 08:34 被阅读0次
    *&---------------------------------------------------------------------*
    *& Title: deleting tables ACCT*                                        *
    *&---------------------------------------------------------------------*
    REPORT ZZTTAMAC.
    TABLES:
      ACCTHD, ACCTIT, ACCTCR.
    
    CONSTANTS:
      PACKAGE_SIZE TYPE I VALUE 1000000. 
    "核心关键点在这里,此处是调整一次性删除多少数据,这个值我的系统的极值点,
    "如果你想使用,请自己去调整这个数值,系统原来的默认值是1000
    
    DATA:
      ACCTHD_KEY_TAB LIKE ACCHD_KEY OCCURS PACKAGE_SIZE WITH HEADER LINE,
      ACCTIT_KEY_TAB LIKE ACCIT_KEY OCCURS PACKAGE_SIZE WITH HEADER LINE.
    DATA:
      BEGIN OF ACCTCR_KEY_TAB OCCURS PACKAGE_SIZE.
            INCLUDE STRUCTURE ACCCR_KEY.
    DATA:
        WAERS LIKE ACCTCR-WAERS,
      END OF ACCTCR_KEY_TAB,
      DEL_COUNT TYPE I.
    
    PARAMETERS: P_TEST AS CHECKBOX DEFAULT 'X'.
    
    * Delete table ACCTHD completely
    
    CLEAR DEL_COUNT.
    IF P_TEST IS INITIAL.
      DO.
    * for runtime-estimations only: Just check how long 1000 deletes
    * would take via taking off the asterix of the following line
    * and commenting off the latter one:
    * DO 1 TIMES.
    *
        SELECT MANDT
               AWTYP
               AWREF
               AWORG
                 FROM ACCTHD
                 INTO  TABLE ACCTHD_KEY_TAB
          UP TO PACKAGE_SIZE ROWS.
    
        IF SY-SUBRC <> 0.
          EXIT.
        ENDIF.
    
        DELETE ACCTHD FROM TABLE ACCTHD_KEY_TAB.
        COMMIT WORK.
        DEL_COUNT = DEL_COUNT + SY-DBCNT.
        REFRESH ACCTHD_KEY_TAB.
        CLEAR ACCTHD_KEY_TAB.
      ENDDO.
      WRITE: / 'Table ACCTHD: ', DEL_COUNT, ' records deleted'.
    ELSE.
      SELECT COUNT(*) FROM ACCTHD INTO DEL_COUNT.
      WRITE: / 'Table ACCTHD: ', DEL_COUNT, ' records read'.
    ENDIF.
    
    * DELETE TABLE ACCTIT COMPLETELY
    CLEAR DEL_COUNT.
    
    IF P_TEST IS INITIAL.
      DO.
    * for runtime-estimations only: Just check how long 1000 deletes
    * would take via taking off the asterix of the following line
    * and commenting off the latter one:
    * DO 1 TIMES.
    *
        SELECT  MANDT
                AWTYP
                AWREF
                AWORG
                POSNR
               FROM ACCTIT
               INTO TABLE ACCTIT_KEY_TAB
          UP TO PACKAGE_SIZE ROWS.
    
        IF SY-SUBRC <> 0.
          EXIT.
        ENDIF.
    
        DELETE ACCTIT FROM TABLE ACCTIT_KEY_TAB.
        COMMIT WORK.
        DEL_COUNT = DEL_COUNT + SY-DBCNT.
        REFRESH ACCTIT_KEY_TAB.
        CLEAR ACCTIT_KEY_TAB.
      ENDDO.
      WRITE: / 'Table ACCTIT: ', DEL_COUNT, ' records deleted'.
    ELSE.
      SELECT COUNT(*) FROM ACCTIT INTO DEL_COUNT.
      WRITE: / 'Table ACCTIT: ', DEL_COUNT, ' records read'.
    ENDIF.
    
    * Delete table ACCTCR completely
    CLEAR DEL_COUNT.
    IF P_TEST IS INITIAL.
      DO.
    * for runtime-estimations only: Just check how long 1000 deletes
    * would take via taking off the asterix of the following line
    * and commenting off the latter one:
    * DO 1 TIMES.
    *
        SELECT MANDT
               AWTYP
               AWREF
               AWORG
               POSNR
               CURTP
               WAERS
                 FROM ACCTCR
               INTO TABLE ACCTCR_KEY_TAB
                  UP TO PACKAGE_SIZE ROWS.
    
        IF SY-SUBRC <> 0.
          EXIT.
        ENDIF.
    
    
        DELETE ACCTCR FROM TABLE ACCTCR_KEY_TAB.
        COMMIT WORK.
        DEL_COUNT = DEL_COUNT + SY-DBCNT.
        REFRESH ACCTCR_KEY_TAB.
        CLEAR ACCTCR_KEY_TAB.
    
      ENDDO.
    
      WRITE: / 'Table ACCTCR: ', DEL_COUNT, ' records deleted'.
    ELSE.
      SELECT COUNT(*) FROM ACCTCR INTO DEL_COUNT.
      WRITE: / 'Table ACCTCR: ', DEL_COUNT, ' records read'.
    ENDIF.
    
    

    相关文章

      网友评论

          本文标题:快速删除acctit表中数据

          本文链接:https://www.haomeiwen.com/subject/gphywktx.html