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: 

how to check background job is active

former_member305388
Active Contributor
0 Kudos

Dear Experts,

I have created a Z program which  schedules a standard program(say SAPREPORT) in background via Job_open, submit program, Job_close. I am reading the table tbtco with jobname and status 'R' to identify if the standard job scheduled in background via submit statement is running or not.

This program works fine if I execute the the Z program in foreground but I need to schedule this as well in background. When I schedule the z program as batch job it is not able to find any entry (sy-subrc = 4) in tbtco table with status R and thus schedules the standard program job again. I am not sure why the program is unable to read the tbtco entry when run as background, I can see the entry when I check thought se11.

The idea is to prevent the standard program from being run in parallel. Please help as how this can be achieved. Thanks.

4 REPLIES 4

ShyamPindiproli
Active Participant
0 Kudos

Hi Srinivas,

You can make alternatively make use of the SAP Standard Function Module : BP_JOB_SELECT

which will get all the Background Jobs for you.

This is also used in the Standard T-Code : SMX, so you can trust that it works.

Regards,

Shyam

0 Kudos

Hi Shyam,

Unfortunately it doesn't seem to work. If i execute the fm and check directly it returns the running jobs but when same is done via z program which itself is running as background job it does not find any running instance for the standard job which has been scheduled. All these standard FM seem to get the value if the z program is run in foreground. Any other solution? Thanks

Additionally I have also tried the FM BP_FIND_JOBS_WITH_PROGRAM and direct select from tbtco.

An interesting thing to note is the z program which is scheduled as background job keeps waiting (delay increases) till the standard scheduled program job has completed.

CALL FUNCTION 'BP_JOB_SELECT'
   EXPORTING
     jobselect_dialog          = 'N'
    JOBSEL_PARAM_IN           = l_jselect
*   ENDDATE                   = '        '
*   ENDTIME                   = '      '
    SELECTION                 = 'AL'
*   ADK_MODE                  = ' '
  IMPORTING
    JOBSEL_PARAM_OUT          = l_jselect
*   LOCAL_CLIENT              =
    NR_OF_JOBS_FOUND          = count
   tables
     jobselect_joblist         = l_joblist
*   JOBNAME_EXT_SEL           =
*   USERNAME_EXT_SEL          =
* CHANGING
*   ERROR_CODE                =
  EXCEPTIONS
    INVALID_DIALOG_TYPE       = 1
    JOBNAME_MISSING           = 2
    NO_JOBS_FOUND             = 3
    SELECTION_CANCELED        = 4
    USERNAME_MISSING          = 5
    OTHERS                    = 6

0 Kudos

Hi,

    Try to schedule your program with the following function modules in sequence.

1) Call function module JOB_OPEN.

2) Use SUBMIT statement and submit your current report.

3) Call function module JOB_CLOSE.

4) Use function module BP_JOB_READ in DO and ENDDO loop to get the job details.

Please find the sample code in the attachment.

Thanks & Regards

Bala Krishna

former_member230486
Contributor
0 Kudos

Hi,

Check the system variable SY-BATCH.