Friday, December 9, 2016

create and start background jobs from abap

    data lv_job_was_released type abap_bool.
    data lv_ret type i.
    data lv_stepcount type btcstepcnt.

    call function 'JOB_OPEN'
      exporting
        jobname          = lv_jobname
      importing
        jobcount         = lv_jobcount
      changing
        ret              lv_ret
      exceptions
        cant_create_job  1
        invalid_job_data 2
        jobname_missing  3
        others           4.

    if sy-subrc <> 0.
      " ...
      return.
    endif.

*    submit (mo_run->ms_run-client_report)
*      using selection-set mv_variant
*      user sy-uname via job mv_jobname number mv_jobcount
*      and return.
* Starting the report with submit, SM37  will display a 

* temporary variant 0.. insteat of the created variant 

    call function 'JOB_SUBMIT'
      exporting
        authcknam               sy-uname
        jobcount                = lv_jobcount
        jobname                 = lv_jobname
        report                  = lv_client_report
        variant                 = lv_variant
      importing
        step_number             lv_stepcount
      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.
      " ...
      return.
    endif.

    call function 'JOB_CLOSE'
      exporting
        jobcount             = lv_jobcount
        jobname              = lv_jobname
        targetsystem         = lv_server
        strtimmed            'X' " start immediately
      importing
        job_was_released     lv_job_was_released
      changing
        ret                  lv_ret
      exceptions
        cant_start_immediate 1
        invalid_startdate    2
        jobname_missing      3
        job_close_failed     4
        job_nosteps          5
        job_notex            6
        lock_failed          7
        invalid_target       8
        others               9.

    if sy-subrc <> 0.
      " ...
      return.
    endif.

No comments:

Post a Comment

SAP ABAP: Determine Timezone for Plant

    DATA:       lt_tzone TYPE STANDARD TABLE OF tznzone WITH DEFAULT KEY,       l_tzone  TYPE tznzone.     " get time zone for plant   ...