Abap程序中删除已完成的后台JOB

很多时候一个程序设定的JOB的时间范围很小,一两分钟跑一次程序,一个程序又拆分N个进程。一天下来已完成的量将无法估量,占用的内存也很大。这时候就可以在程序中加入删除后台JOB的代码。
先根据程序名查询JOB名称以及JOB编号等信息

SELECT *
       FROM tbtcp
       INTO CORRESPONDING FIELDS OF TABLE lt_joblist
       WHERE (progname = 'XXX1' OR
               progname = 'XXX2' ) AND
             sdldate <= sy-datum AND
             sdldate >= lv_date.

再循坏查询出来的JOB,进行状态的获取,满足已完成的状态的JOB就删除掉。

     LOOP AT lt_joblist INTO lw_job.
       CLEAR lv_status.
       CALL FUNCTION 'BDL_READ_JOB_STATUS'
         EXPORTING
           jobname       = lw_job-jobname
           jobnumber     = lw_job-jobcount
         IMPORTING
           jobstatus     = lv_status
         EXCEPTIONS
           job_not_found = 1
           OTHERS        = 2.
       IF sy-subrc <> 0.                                    "#EC NEEDED
       ENDIF.
       IF lv_status EQ 'F' .

         CALL FUNCTION 'BP_JOB_DELETE'   "delete job
                 EXPORTING
                   jobcount                 = lw_job-jobcount
                   jobname                  = lw_job-jobname
                   forcedmode               = 'X'
                 EXCEPTIONS
                   cant_delete_event_entry  = 1
                   cant_delete_job          = 2
                   cant_delete_joblog       = 3
                   cant_delete_steps        = 4
                   cant_delete_time_entry   = 5
                   cant_derelease_successor = 6
                   cant_enq_predecessor     = 7
                   cant_enq_successor       = 8
                   cant_enq_tbtco_entry     = 9
                   cant_update_predecessor  = 10
                   cant_update_successor    = 11
                   commit_failed            = 12
                   jobcount_missing         = 13
                   jobname_missing          = 14
                   job_does_not_exist       = 15
                   job_is_already_running   = 16
                   no_delete_authority      = 17
                   OTHERS                   = 18.
         IF sy-subrc <> 0.                                  "#EC NEEDED
         ENDIF.
       ENDIF.
     ENDLOOP.

有疑问可以留言哈·

你可能感兴趣的:(Abap程序中删除已完成的后台JOB)