Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

back ground process using abap program

Former Member
0 Kudos
89

Hi,

How to create background process using job_open,Job_submit,job_close function modules

1 REPLY 1

former_member189059
Active Contributor
0 Kudos
54


DATA: lv_job_name         LIKE tbtco-jobname,
lv_job_nr           LIKE tbtco-jobcount,
lv_job_released     TYPE c,
lv_job_start_sofort TYPE c,
lv_print_parameters TYPE pri_params.
lv_job_name = 'Z_BGPROGRAM'.

  CALL FUNCTION 'JOB_OPEN'
    EXPORTING
      jobname          = lv_job_name
    IMPORTING
      jobcount         = lv_job_nr
    EXCEPTIONS
      cant_create_job  = 1
      invalid_job_data = 2
      jobname_missing  = 3
      OTHERS           = 4.
  IF syst-subrc = 0.
" submit job with all the selection screen params...
    SUBMIT (lv_job_name)
        WITH applfile = applfile " these are the parameters of the background program
        WITH p_lines = p_lines
        USER syst-uname " you must use this
       VIA JOB lv_job_name NUMBER lv_job_nr AND RETURN.
    IF sy-subrc = 0.
      CALL FUNCTION 'JOB_CLOSE'
        EXPORTING
          jobcount             = lv_job_nr
          jobname              = lv_job_name
          strtimmed            = 'X'
        IMPORTING
          job_was_released     = lv_job_released
        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 syst-subrc <> 0.
        MESSAGE i162(00) WITH
        'An error occured while closing the background job.'.
        STOP.
      ENDIF.
    ENDIF.
  ENDIF.
  SKIP 1.
  WRITE: / 'Background process', lv_job_name , 'called successfully' NO-GAP.
  WRITE: / 'You can check the job in transaction SM37'.