Submit a program in background via job

Submit a program in background via job

The submited program with method below can be monitored in SM37.


    DATA: lv_number           TYPE tbtcjob-jobcount,
          lv_name             TYPE tbtcjob-jobname.

    lv_name =  'Relevant Job name'.

    CALL FUNCTION 'JOB_OPEN'
      EXPORTING
        jobname          = lv_name
      IMPORTING
        jobcount         = lv_number
      EXCEPTIONS
        cant_create_job  = 1
        invalid_job_data = 2
        jobname_missing  = 3
        OTHERS           = 4.

    IF sy-subrc = 0.
      SUBMIT z_report_to_call  WITH p_par1    = lv_param1
                               WITH p_par2    = lv_par2
                               WITH s_matnr  IN lr_matnr
                               WITH p_flag    = 'X'
                               VIA JOB lv_name NUMBER lv_number
                               AND RETURN.

      IF sy-subrc = 0.
        CALL FUNCTION 'JOB_CLOSE'
          EXPORTING
            jobcount             = lv_number
            jobname              = lv_name
            strtimmed            = 'X'
          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 > 1.
          MESSAGE i054(s_cus_img_activity).
          " Background job could not be started.
          " Le job d’arrière-plan n’a pas pu être lancé.
        ENDIF.

      ELSE.
        " Display error returned by SUBMIT of program
        DATA(ls_msg) = cl_abap_submit_handling=>get_error_message( ).
        MESSAGE ID ls_msg-msgid
                TYPE 'I'
                NUMBER ls_msg-msgno
                WITH ls_msg-msgv1 ls_msg-msgv2 ls_msg-msgv3 ls_msg-msgv4
                DISPLAY LIKE ls_msg-msgty.
      ENDIF.
    ENDIF.

About the author

fjourneau administrator

Hi, I'm Florian Journeau, SAP ABAP R3 Freelance, based in Toulouse, France. You want to know more about me, have a look on my CV : cv.fjourneau.net.

Leave a Reply