Job基础

SAP后台JOB相关系统表

TBTC*

主要的有 :

  • TBTCO - 作业状态概述表
  • TBTCP - 批作业步骤概述

1696729965169.png

JOB的状态

可以使用系统函数查看 BDL_READ_JOB_STATUS 或者是自己去表 TBTCO 中查找(根据STATUS 字段判断是否完成)。

R 活动的(运行中)
Y 就绪的
P 已调度的
S 已释放
A 已取消(出错终止)
F 已完成(结束)
Z Released/Susp.(无中文)

JOB运行时间

TBTCO中有开始日期开始时间和结束日期结束时间,两者直接相减就得出JOB运行的时间。

JOB日志查看

系统中的日志好像是没有存放在系统表而是文件中,可以通过函数 BP_JOBLOG_READ 获取,传入JOB名和JOB编号就可以获得日志信息。
例如:获取失败日志
 

 DATA:lt_log TYPE TABLE OF tbtc5 WITH HEADER LINE.

CALL FUNCTION 'BP_JOBLOG_READ'
  EXPORTING
    client                = sy-mandt
    jobcount              = lw_job-jobcount
    jobname               = lw_job-jobname
  TABLES
    joblogtbl             = lt_log
  EXCEPTIONS
    cant_read_joblog      = 1
    jobcount_missing      = 2
    joblog_does_not_exist = 3
    joblog_is_empty       = 4
    joblog_name_missing   = 5
    jobname_missing       = 6
    job_does_not_exist    = 7
    OTHERS                = 8.
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

Job状态的更改

可以通过函数BP_JOB_MODIFY来修改。

*&---------------------------------------------------------------------*
*&      Form  MODIFY_JOB_NAME
*&---------------------------------------------------------------------*
*       Modify user name for job owner
*----------------------------------------------------------------------*
*      -->P_LV_JOBNUM  text
*      -->P_GV_JOBNAME  text
*----------------------------------------------------------------------*
FORM modify_job_name  USING    p_lv_jobnum
                               p_gv_jobname.
  DATA: ls_jobhead TYPE tbtcjob,
        lt_jobstep TYPE STANDARD TABLE OF tbtcstep.

  CALL FUNCTION 'BP_JOB_READ'
    EXPORTING
      job_read_jobcount     = p_lv_jobnum
      job_read_jobname      = p_gv_jobname
      job_read_opcode       = '20'
    IMPORTING
      job_read_jobhead      = ls_jobhead
    TABLES
      job_read_steplist     = lt_jobstep
    EXCEPTIONS
      invalid_opcode        = 1
      job_doesnt_exist      = 2
      job_doesnt_have_steps = 3
      OTHERS                = 4.
  IF sy-subrc <> 0.
  ENDIF.
*** ls_jobhead-sdluname = 'BATCH_NEW'.
  CALL FUNCTION 'BP_JOB_MODIFY'
    EXPORTING
      dialog                     = 'N'
      jobcount                   = p_lv_jobnum
      jobname                    = p_gv_jobname
***   new_jobhead                = ls_jobhead
      opcode                     = '18'
    IMPORTING
      modified_jobhead           = ls_jobhead
    TABLES
      new_steplist               = lt_jobstep
    EXCEPTIONS
      cant_derelease_job         = 1
      cant_enq_job               = 2
      cant_read_jobdata          = 3
      cant_release_job           = 4
      cant_set_jobstatus_in_db   = 5
      cant_start_job_immediately = 6
      cant_update_jobdata        = 7
      eventcnt_generation_error  = 8
      invalid_dialog_type        = 9
      invalid_new_jobdata        = 10
      invalid_new_jobstatus      = 11
      invalid_opcode             = 12
      invalid_startdate          = 13
      job_edit_failed            = 14
      job_modify_canceled        = 15
      job_not_modifiable_anymore = 16
      nothing_to_do              = 17
      no_batch_on_target_host    = 18
      no_batch_server_found      = 19
      no_batch_wp_for_jobclass   = 20
      no_modify_privilege_given  = 21
      no_release_privilege_given = 22
      no_startdate_no_release    = 23
      target_host_not_defined    = 24
      tgt_host_chk_has_failed    = 25
      invalid_targetgroup        = 26
      conflicting_targets        = 27
      OTHERS                     = 28.
  IF sy-subrc <> 0.
  ENDIF.
ENDFORM.

上面的函数中需要注意一个参数:opcode ,下面则是这个参数的具体对照解释。

btc_edit_btcctl_tbl       LIKE btch0000-int4 VALUE  1,
  btc_show_btcctl_tbl       LIKE btch0000-int4 VALUE  2,
  btc_edit_user_eventids    LIKE btch0000-int4 VALUE  3,
  btc_show_user_eventids    LIKE btch0000-int4 VALUE  4,
  btc_edit_system_eventids  LIKE btch0000-int4 VALUE  5,
  btc_show_system_eventids  LIKE btch0000-int4 VALUE  6,
  btc_edit_steplist         LIKE btch0000-int4 VALUE  7,
  btc_show_steplist         LIKE btch0000-int4 VALUE  8,
  btc_show_variantlist      LIKE btch0000-int4 VALUE  9,
  btc_create_job            LIKE btch0000-int4 VALUE 10,
  btc_edit_job              LIKE btch0000-int4 VALUE 11,
  btc_show_job              LIKE btch0000-int4 VALUE 12,
  btc_check_only            LIKE btch0000-int4 VALUE 13,
  btc_edit_startdate        LIKE btch0000-int4 VALUE 14,
  btc_show_startdate        LIKE btch0000-int4 VALUE 15,
  btc_modify_whole_job      LIKE btch0000-int4 VALUE 16,
  btc_release_job           LIKE btch0000-int4 VALUE 17,
  btc_derelease_job         LIKE btch0000-int4 VALUE 18,
  btc_read_jobhead_only     LIKE btch0000-int4 VALUE 19,
  btc_read_all_jobdata      LIKE btch0000-int4 VALUE 20,
  btc_joblist_edit          LIKE btch0000-int4 VALUE 21,
  btc_joblist_show          LIKE btch0000-int4 VALUE 22,
  btc_joblist_select        LIKE btch0000-int4 VALUE 23,
  btc_joblog_show           LIKE btch0000-int4 VALUE 24,
  btc_edit_omset            LIKE btch0000-int4 VALUE 25,
  btc_show_omset            LIKE btch0000-int4 VALUE 26,
  btc_show_oms_sdl_tbl      LIKE btch0000-int4 VALUE 27,
  btc_show_xpgm_list        LIKE btch0000-int4 VALUE 28,
  btc_close_job             LIKE btch0000-int4 VALUE 29,
  btc_varjoblist_select     LIKE btch0000-int4 VALUE 30,
  btc_varlist_select        LIKE btch0000-int4 VALUE 31,
  btc_performance_list      LIKE btch0000-int4 VALUE 32,
  btc_performance_info      LIKE btch0000-int4 VALUE 33,
  btc_batchproces_list      LIKE btch0000-int4 VALUE 34,
  BTC_DONT_READ_PRIPARAMS   LIKE BTCH0000-INT4 VALUE 35, 
  btc_xbp_all_jobdata       LIKE btch0000-int4 VALUE 36, 
  btc_xbp_jobhead_only      LIKE btch0000-int4 VALUE 37.  

ABAP后台JOB数量控制

DATA: BEGIN OF LT_JOBS OCCURS 0 ,
          JOBNAME  TYPE BTCJOB,
          STRTDATE TYPE BTCXDATE,
          STRTTIME TYPE BTCXTIME,
          ENDDATE  TYPE BTCXDATE,
          ENDTIME  TYPE BTCXTIME,
        END OF LT_JOBS.
  DATA: F_JOBNAME TYPE STRING VALUE 'Z_%'.
  DATA: V_ACTIVE TYPE INT1.
  SELECT JOBNAME
  INTO TABLE LT_JOBS
  FROM TBTCO
  WHERE ( JOBNAME LIKE F_JOBNAME )
  AND STATUS EQ 'R'.
  IF SY-SUBRC = 0 .
    DESCRIBE TABLE LT_JOBS LINES V_ACTIVE .
    IF V_ACTIVE >= 5.
      MESSAGE '有正在运行的任务,此次任务取消。' TYPE 'S' DISPLAY LIKE 'E'.
    ENDIF .
  ENDIF.