Application Development and Automation 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: 
Read only

Job Scheduling

former_member576008
Active Participant
0 Likes
754

Hi,

My requirement is to schedule a job for every 5 mins, simple isn't it ! But it should be triggered exactly after 5 mins of its previous jobs ends time.

For exp:

Here all the jobs denotes same report and same variant.

Job1 executed for 3 mins and ended at 7:05

Job2 should start at 7:10, say Job2 executed for 12 mins and ended at 7:22

Job3 should start at 7:27.

For this i have created an event in SM62 and Z report to raise the event.

In the Z report, selection screen i have given event name and actual Job to be scheduled.

This Z report will be scheduled periodically for every 5 mins and it will check the actual job status Released or not.

If it is released it will not raise any event, otherwise it will raise an event,

To execute it for every 5 mins, i am using FM to get the last ended jobs status and time.

To the last ended time i am adding 5 mins and subtracting the current, the time difference will be wait time.

Though this is working fine for most of the time, but some times its sub sequent jobs are executed in less than few seconds.

Can someone help me on this, let me know if you require code for this.

Regards,

Nandha

1 ACCEPTED SOLUTION
Read only

paul_bakker2
Active Contributor
0 Likes
700

Hi,

I don't quite understand your logic, but maybe this design would work:

- Add a 'wait 5 minutes' step to your progam XYZ

- Schedule program XYZ to run in job ABC

- Schedule another job ABC to run after the first ABC job terminates (use the start condition 'After Job').

This means a new ABC job will be spawned at the moment the last job finishes.

The program will do nothing for exactly 5 minutes, then spring into action.

(Alternatively, job ABC could contain two program steps; the first program does nothing but wait five minutes).

cheers

Paul

Hi,

My requirement is to schedule a job for every 5 mins, simple isn't it ! But it should be triggered exactly after 5 mins of its previous jobs ends time.

For exp:

Here all the jobs denotes same report and same variant.

Job1 executed for 3 mins and ended at 7:05

Job2 should start at 7:10, say Job2 executed for 12 mins and ended at 7:22

Job3 should start at 7:27.

For this i have created an event in SM62 and Z report to raise the event.

In the Z report, selection screen i have given event name and actual Job to be scheduled.

This Z report will be scheduled periodically for every 5 mins and it will check the actual job status Released or not.

If it is released it will not raise any event, otherwise it will raise an event,

To execute it for every 5 mins, i am using FM to get the last ended jobs status and time.

To the last ended time i am adding 5 mins and subtracting the current, the time difference will be wait time.

Though this is working fine for most of the time, but some times its sub sequent jobs are executed in less than few seconds.

Can someone help me on this, let me know if you require code for this.

Regards,

Nandha

3 REPLIES 3
Read only

paul_bakker2
Active Contributor
0 Likes
701

Hi,

I don't quite understand your logic, but maybe this design would work:

- Add a 'wait 5 minutes' step to your progam XYZ

- Schedule program XYZ to run in job ABC

- Schedule another job ABC to run after the first ABC job terminates (use the start condition 'After Job').

This means a new ABC job will be spawned at the moment the last job finishes.

The program will do nothing for exactly 5 minutes, then spring into action.

(Alternatively, job ABC could contain two program steps; the first program does nothing but wait five minutes).

cheers

Paul

Read only

0 Likes
700

Hi Paul,

Thanks for your reply. Below is my source code.

The program i am mentioning is RSNAST00, with a variant.

I want to run this job with 5 mins of wait to the previous job completed time.

I will try the logic, what you have proposed.

data: t_joblist type table of tbtcjmoni,
       wa_joblist type tbtcjmoni,
       lv_timediff type sy-uzeit,
       lv_fivemins type sy-uzeit.

data: job_head like tbtcjob.

data:lv_endtime type sy-uzeit,
       lv_starttime type sy-uzeit,
       lv_wait type i.

*selection screen with event name and second job name
parameters:p_event type btceventid,
           p_jobnam type tbtcjob-jobname.

start-of-selection.

*FM to get the job status

   call function 'BP_JOB_MONI'
     exporting
       jobname               = p_jobnam
*   ENDDATE               = '        '
*   ENDTIME               = '      '
     tables
       joblist               = t_joblist
    exceptions
      jobname_missing       = 1
      no_jobs_found         = 2
      other_error           = 3
      others                = 4
             .
   if sy-subrc = 0.

     read table t_joblist with key jobname = p_jobnam
                                   status = 'R' transporting no fields.
*Check if there any job with status R, that means job is ready to run
*If not event should be raised, that why checking sy-subrc ne 0
     if sy-subrc ne 0.
       clear: lv_endtime,lv_starttime,lv_timediff,wa_joblist,lv_fivemins.
*The internal table will contain all one entry
       read table t_joblist into wa_joblist index 1.
       if sy-subrc eq 0.
*the logic is get the last finished job time and add 5 mins to it
*When this report job starts, get the time difference between 2 job timings
*And the differnce is the wait time, wait is required to make the job 5 mins wait
*for its next run
         lv_endtime = wa_joblist-endtime.
         lv_fivemins = '000600'.
         lv_starttime = lv_endtime + lv_fivemins.
         lv_timediff = lv_starttime - sy-uzeit.

         lv_wait = lv_timediff+2(2).
         lv_wait = lv_wait * 60.
         wait up to lv_wait seconds.
*Us this function module to raise the event, given in the selection screen
         call function 'BP_EVENT_RAISE'
           exporting
             eventid                      = p_event
*     EVENTPARM                    = ' '
*     TARGET_INSTANCE              = ' '
          exceptions
            bad_eventid                  = 1
            eventid_does_not_exist       = 2
            eventid_missing              = 3
            raise_failed                 = 4
            others                       = 5
                   .
         write : 'job ', p_jobnam, 'started at', sy-datum, sy-uzeit.

       else.
*This else spot will run only once, that is at the time of first schedule.
         call function 'BP_EVENT_RAISE'
           exporting
             eventid                      = p_event
*               EVENTPARM                    = ' '
*               TARGET_INSTANCE              = ' '
           exceptions
            bad_eventid                  = 1
            eventid_does_not_exist       = 2
            eventid_missing              = 3
            raise_failed                 = 4
            others                       = 5.

         write : 'job ', p_jobnam, 'started at', sy-datum, sy-uzeit.

       endif.

     else.

       write: 'job ', p_jobnam, 'is still running'.

     endif.

   endif.

Read only

0 Likes
700

Thanks Paul.

I have added 5 mins to report and a FM in it to raise an event.

Later created 2 jobs with 2 steps, first step standard report and in the step Z report.

First job will run only once and the second job will be triggered from first job second step.

Second Job will go recursive. Thanks.

Regards,

NK