AS/400 CL to submit a Jobscheduler entry wont loop

35 pts.
Tags:
AS/400
AS/400 - CL Command
I have created a command which simply calls a CL called Booking which is below. 

It submits a program PC832U and re-adds itself to the job scheduler. So basically it is running every 5 minutes until 2pm. 

First call runs great. It runs the program and adds itself in the scheduler for 5 mins later. However, it should loop over and over but it only runs once and then wont reschedule itself. 

Any idea why ?

Thanks

Adam

PGM                                                                             
             DCL        VAR(&CMD)      TYPE(*CHAR) LEN(256)                     
             DCL        VAR(&TIME)     TYPE(*CHAR) LEN(6)                       
             DCL        VAR(&HOUR)     TYPE(*CHAR) LEN(2)                       
             DCL        VAR(&MINUTE)   TYPE(*CHAR) LEN(2)                       
             DCL        VAR(&ENDHOUR)  TYPE(*DEC)  LEN(2 0) VALUE(16) /*01->23*/
             DCL        VAR(&INTERVAL) TYPE(*DEC)  LEN(2 0) VALUE(5) /*01->59*/ 
             DCL        VAR(&WHOUR)    TYPE(*DEC)  LEN(2 0)                     
             DCL        VAR(&WMINUTE)  TYPE(*DEC)  LEN(2 0)                     
             DCL        VAR(&DUMMY)    TYPE(*DEC)  LEN(3 0)                     
                                                                                
             /* WHAT TIME IS IT? */                                             
             RTVSYSVAL  SYSVAL(QTIME)   RTNVAR(&TIME)                           
             RTVSYSVAL  SYSVAL(QHOUR)   RTNVAR(&HOUR)                           
             RTVSYSVAL  SYSVAL(QMINUTE) RTNVAR(&MINUTE)                         
                                                                                
             /* MAKE NUMERIC */                                                 
             CHGVAR     VAR(&WHOUR)   VALUE(&HOUR)                              
             CHGVAR     VAR(&WMINUTE) VALUE(&MINUTE)                            
                                                                             
             /* STOP IF TIME HAS PASSED END-TIME */                          
             IF         COND(&WHOUR >= &ENDHOUR) THEN(RETURN)                
                                                                             
             /* PREPARE VALUES FOR CALCULATION OF NEXT EXECUTION */          
             CHGVAR     VAR(&DUMMY) VALUE(&WMINUTE + &INTERVAL)              
             IF         COND(&DUMMY > 59) THEN(DO)                           
               CHGVAR     VAR(&WHOUR) VALUE(&WHOUR + 1)                      
               CHGVAR     VAR(&WMINUTE) VALUE(&DUMMY - 60)                   
               ENDDO                                                         
             ELSE       CMD(CHGVAR VAR(&WMINUTE) VALUE(&WMINUTE + &INTERVAL))
                                                                             
             /* CALCULATE SCHEDULED TIME FOR NEXT EXECUTION */               
             CHGVAR     VAR(&HOUR) VALUE(&WHOUR)                             
             CHGVAR     VAR(&MINUTE) VALUE(&WMINUTE)                         
             CHGVAR     VAR(&TIME) VALUE(&HOUR *TCAT &MINUTE *TCAT '01')     
                                                                             
             /* PUT A SCHEDULED JOB INTO THE JOB-SCHEDULER */                
             ADDJOBSCDE JOB(OP5BOOK) CMD(AULSPRX3/BOOK) FRQ(*ONCE) +         
                          SCDDATE(*CURRENT) SCDTIME(&TIME)                   
                                                                      
             /* PUT PROCESSING HERE */                                                               
             SBMJOB     CMD(CALL PGM(AULSPRX3/PC832U)) JOB(PRODBOOK)  
                                                                      
   ENDPGM:   ENDPGM                                                   

Answer Wiki

Thanks. We'll let you know when a new response is added.

Try just using the SBMJOB command with the schedule time (SCDTIME) parm five minutes in the future.  No need to clutter up your system with a lot job schedule entries.  You may want to use a job schedule entry to launch the process every day, then let the job submit itself to run again.

Discuss This Question: 5  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • ToddN2000
    I am curious as to what the job you are submitting with the SBMJOB command is doing. Is the code listed that program? 

    You could jus put a simple loop in and stack all the jobs in the jobscheduler at 5 minute intervals until you reach your cut-off time of 2pm.

    I see no loop back in you code. After the ADDJOBSCDE and SMBJOB it just ends.

    Is there another process that must complete before the next job scheduler job runs?
    15,605 pointsBadges:
    report
  • adamkm

    Hi Todd

    Thanks for the reply.

    The SBMJOB is running a program that processes transactions from our works order bookings from the temporary file into the live booking files. They are put into a temporary file because overnight they can continue to book while the subsystems are down for backups, then the program runs again at 4am until 11pm (it only runs until 2pm while I was testing it). For all intent purposes that job is kinda irrelevant :)

    I could add the ADDJOBSCDE command like 100 times in the RPG but that's a bit sloppy, I'm probably going to need to tweak the timings on the SBMJOB.

    There is no loop back in the code, the ADDJOBSCDE is adding this little program to job scheduler.

    It runs, adds itself for 5 mins later, sumbits the SMBJOB. Runs 5 mins later, reschedules itself for 5 mins later and submits the SMBJOB.

    This repeats until:

    IF         COND(&WHOUR >= &ENDHOUR) THEN(RETURN)

    Then ends. Which is the time specified earlier.

     

    What's weird is it does sometimes run for over and hour before it fails to schedule itself again. I don't understand that part. Normally it runs the SBMJOB once, schedules itself, runs the SBMJOB when it hits the first schedule then fails to reschedule itself.

     

    Thanks

     

    Adam

    35 pointsBadges:
    report
  • adamkm

    "There is no loop back in the code, the ADDJOBSCDE is adding this little program to job scheduler. "

     

    Sorry, to make this part clearer, the ADDJOBSCDE is adding this same program back into the job scheduler. AULSPRX3/BOOK is this program I posted.

    35 pointsBadges:
    report
  • pdraebel
    To me it looks like the code is Ok. I ran it and jobs are Scheduled as desired. Have a look at the logging of jobs to see if there are error messages, possibly on the user lacking authority to work with the Job Schedule entries.
    3,230 pointsBadges:
    report
  • adamkm

    Thanks for testing it pdraebel :)

    Ah right it could be that the user I submit it from, which is a machine manager user, doesn't have rights or its having issues with the library lists. It does seem to work better when I submit it myself. It was up for over an hour yesterday and stopped correctly as timed.

    I'll report back.

     

    35 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following