Prevent multiple program submissions
You may want to prevent users to submit the same program twice for performance reasons. Here is a code snippet to prevent this.
Continue Reading This Article
Enjoy this article as well as all of our content, including E-Guides, news, tips and more.
*---------------------------------------------------------------------* * FORM check_running * *---------------------------------------------------------------------* * ........ * *---------------------------------------------------------------------* FORM check_running. * * For some background update jobs, you might want to stop the * user from submitting the jobs twice. * * Do this checks to prevent the users from submitting the * same background job twice. * * Perform the checks before starting your programs. * do this check only if sy-batch = 'X' * * * TYPES : BEGIN OF x_job_data, jobname LIKE tbtco-jobname, jobcount LIKE tbtco-jobcount, strtdate LIKE tbtco-strtdate, strttime LIKE tbtco-strttime, END OF x_job_data. DATA: curr_jobname LIKE tbtcm-jobname, curr_jobcount LIKE tbtcm-jobcount, g_jobcount LIKE tbtcjob-jobcount, g_jobname LIKE tbtcjob-jobname, t_job_table TYPE STANDARD TABLE OF x_job_data WITH HEADER LINE, t_joblog TYPE STANDARD TABLE OF tbtc5 WITH HEADER LINE, t_jobstep TYPE STANDARD TABLE OF tbtcstep WITH HEADER LINE. * * Get own jobdata CALL FUNCTION 'GET_JOB_RUNTIME_INFO' IMPORTING jobcount = curr_jobcount jobname = curr_jobname EXCEPTIONS no_runtime_info = 1 OTHERS = 2. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. * read all other running jobs SELECT * FROM tbtco INTO CORRESPONDING FIELDS OF TABLE t_job_table WHERE jobcount <> curr_jobcount AND strtdate = sy-datum AND strttime < sy-uzeit AND status = 'R'. * IF sy-subrc = 0. LOOP AT t_job_table. g_jobcount = t_job_table-jobcount. g_jobname = t_job_table-jobname. * Read all jobsteps belonging to job CALL FUNCTION 'BP_JOB_READ' EXPORTING job_read_jobcount = g_jobcount job_read_jobname = g_jobname job_read_opcode = '20' * JOB_STEP_NUMBER = * importing * job_read_jobhead = TABLES job_read_steplist = t_jobstep * changing * ret = EXCEPTIONS invalid_opcode = 1 job_doesnt_exist = 2 job_doesnt_have_steps = 3 OTHERS = 4 . IF sy-subrc = 0. * check if current program is part of the job LOOP AT t_jobstep. IF t_jobstep-program = sy-cprog. * program found, issue an error-message MESSAGE i100 WITH 'Please wait ' 'Program is already part of job'. MESSAGE a999 WITH g_jobname 'which is started on ' t_job_table-strtdate t_job_table-strttime. ENDIF. ENDLOOP. ENDIF. ENDLOOP. ENDIF. ENDFORM.