Background job - ensure sequential processing

Sometimes it's important to ensure, that particular background job is processed only once and to avoid parallel, concurent starts. There are many ways to implement the appropriate check, for example using locks or evaluating the list of running jobs.

For the second idea, see a simple coding below.
REPORT zbtc_single.

DATA:
  ls_jobsel     TYPE btcselect,
  lt_joblist    TYPE TABLE OF tbtcjob,
  ls_joblist    TYPE tbtcjob,
  lv_nr_of_jobs TYPE i.

ls_jobsel-jobname = sy-cprog.
ls_jobsel-ready   = 'X'.
ls_jobsel-running = 'X'.

CALL FUNCTION 'BP_JOB_SELECT'
  EXPORTING
    jobselect_dialog    = 'N'
    jobsel_param_in     = ls_jobsel
  IMPORTING
    nr_of_jobs_found    = lv_nr_of_jobs
  TABLES
    jobselect_joblist   = lt_joblist
  EXCEPTIONS
    invalid_dialog_type = 1
    jobname_missing     = 2
    no_jobs_found       = 3
    selection_canceled  = 4
    username_missing    = 5
    OTHERS              = 6.

CHECK lv_nr_of_jobs = 1.

* ... further processing
See other related notes in my infodepot:
Submit program RFBIBL00 and display protocol from your ABAP Display protocol of batch input processing - transaction SM35
Full list of examples in my infodepot

If you have a question, have found an error or just want to contact me, please use this form.

Copyright (C) 2011 http://www.kerum.pl/infodepot/

Disclaimer: I am not affiliated or related to any division or subsidiary of SAP AG.
Trademarks or registered trademarks of any products or companies referred to on this site belong to those companies.
Anyone using the given solutions, is doing it under his/her own responsibility and at own risk.