轉:ABAP報表後台運行

來源:互聯網
上載者:User

*&---------------------------------------------------------------------*
*& Report  Z_BARRY_SET_JOB                                             *
*&                                                                     *
*&---------------------------------------------------------------------*
*&  設定後台Job,更多功能請看函數組:BTCH                              *
*&---------------------------------------------------------------------*

REPORT  z_barry_set_job                         .

DATA: jobcount LIKE tbtcjob-jobcount.
DATA: abort TYPE c,
      finish TYPE c,
      prelim TYPE c,
      ready TYPE c,
      run TYPE c,
      sched TYPE c.

PARAMETERS: p_name LIKE tbtcjob-jobname OBLIGATORY DEFAULT 'Z_BARRY_TEST_JOB',
            p_date LIKE sy-datum OBLIGATORY,
            p_time LIKE sy-uzeit OBLIGATORY.
SELECT-OPTIONS s_rept FOR sy-repid NO INTERVALS OBLIGATORY .

START-OF-SELECTION.
  CALL FUNCTION 'JOB_OPEN' "定義一個Job
    EXPORTING
      jobname          = p_name
    IMPORTING
      jobcount         = jobcount  "Job id
    EXCEPTIONS
      cant_create_job  = 1
      invalid_job_data = 2
      jobname_missing  = 3
      OTHERS           = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  LOOP AT s_rept .
    CALL FUNCTION 'JOB_SUBMIT'  "Scheduled 這個Job
      EXPORTING
        authcknam               = sy-uname
        jobcount                = jobcount
        jobname                 = p_name
        report                  = s_rept-low
*        VARIANT                 = 'TEST'
      EXCEPTIONS
        bad_priparams           = 1
        bad_xpgflags            = 2
        invalid_jobdata         = 3
        jobname_missing         = 4
        job_notex               = 5
        job_submit_failed       = 6
        lock_failed             = 7
        program_missing         = 8
        prog_abap_and_extpg_set = 9
        OTHERS                  = 10.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
  ENDLOOP.

  CALL FUNCTION 'JOB_CLOSE'  "Release 這個Job
    EXPORTING
      jobcount             = jobcount
      jobname              = p_name
      sdlstrtdt            = p_date
      sdlstrttm            = p_time
    EXCEPTIONS
      cant_start_immediate = 1
      invalid_startdate    = 2
      jobname_missing      = 3
      job_close_failed     = 4
      job_nosteps          = 5
      job_notex            = 6
      lock_failed          = 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.

  CALL FUNCTION 'SHOW_JOBSTATE'
    EXPORTING
      jobcount         = jobcount
      jobname          = p_name
    IMPORTING
      aborted          = abort
      finished         = finish
      preliminary      = prelim
      ready            = ready
      running          = run
      scheduled        = sched
    EXCEPTIONS
      jobcount_missing = 1
      jobname_missing  = 2
      job_notex        = 3
      OTHERS           = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  WRITE : / 'Canceled              :' , abort ,
          / 'Finished              :' , finish,
          / 'Scheduled Temporarily :' , prelim,
          / 'Ready for Execution   :' , ready,
          / 'Active                :' , run,
          / 'Scheduling Released   :' , sched.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.