Determine if a submitted job has completed

75 pts.
Tags:
CL Program
iSeries
QUSRJOBI
Hello ALL --- I have a CL program that executes a command which calls a CL utility program. The utility program submits a job that involves the building of a save file. The original CL program will then restore the contents of the save file into a library and obviously must wait until the submitted process has completed. Is there a utility or API - I looked at QUSRJOBI and I'm not sure that's exactly what I need - that will allow me to do accomplish this? Being pointed to a similar example would be very helpful. Thanks so much for your help! I look forward to hearing from someone as soon as possible. Mike Chance Product Support Specialist Catamaran (formerly SXC Health Solutions) 2441 Warrenville Road, Suite 610 Lisle, IL 60532-3642

Software/Hardware used:
iSeries

Answer Wiki

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

Discuss This Question: 6  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
  • CharlieBrowne
    There are ways to have the initial program wait for the submitted job to wait, but that is not the best approach. Your two best options are: 1. Change the program the program that builds the *SAVF to also do the restore. 2. Make sure the job that gets submitted to build the *SAVF is going to a JOBQ that is single threaded. Then change the initial program to submit the restore to the same jobq instead of waiting for the *SAVF to be built.
    41,370 pointsBadges:
    report
  • TomLiotta
    The SBMJOB command has a MSGQ() parameter. When the submitted job completes, a *COMP message is sent to that message queue. The way to wait on a sumitted job is to wait on a completion message for that job to arrive on that message queue. -- Tom
    125,585 pointsBadges:
    report
  • mikechance812
    No offense to Charlie - I appreciate your feedback very much - but what Tom is describing fits my application much better. Not being a huge CL developer, would you be able to give me a generic example of how the looping logic for "waiting on a completion message...to arrive" would look? I'd really appreciate that. Thanks again for your time!
    75 pointsBadges:
    report
  • TomLiotta
    The following isn't a loop, but it should illustrate okay. Generally a loop wouldn't be needed, but it's certainly possible. If looping becomes needed, it can be added for the statements at the end.  
    pgm
    
       dcl   &jbName      *char    10
       dcl   &jbUser      *char    10
       dcl   &jbNbr       *char     6
    
       dcl   &msgdta      *char    46
       dcl   &msgid       *char     7     value( ' ' )
       dcl   &msgkey      *char     4     value( ' ' )
    
    /* +
       Setting up for testing. Ignore error if already created... +
    */
    
       crtmsgq     QGPL/CHKSBMJOB
       monmsg    ( cpf2112 )  exec( do )
          rcvmsg     msgtype( *LAST ) rmv( *YES )
          monmsg   ( cpf0000 )
       enddo
    
    /* +
       Submit a test job... +
    */
    
       sbmjob      cmd( DLYJOB DLY(30) ) job( SBMTSTMSG ) +
                     msgq( QGPL/CHKSBMJOB )
    
    /* +
       Check the job name/user/number; no wait needed... +
    */
    
       rcvmsg   msgtype( *COMP ) rmv( *NO ) +
                  keyvar( &msgkey ) +
                  msgdta( &msgdta ) msgid( &msgid )
    
       select
          when ( &msgid *eq 'CPC1221' )  do
             chgvar   &jbName    %sst( &msgdta  1 10 )
             chgvar   &jbUser    %sst( &msgdta 11 10 )
             chgvar   &jbNbr     %sst( &msgdta 21  6 )
             dmpclpgm
             rmvmsg msgkey( &msgkey )
             enddo
          when ( &msgid *eq '       ' )  do
             sndmsg ( '0. No *COMP' ) tousr( *REQUESTER )
             return
             enddo
          otherwise  do
             sndmsg ( '1.' *bcat &msgid ) tousr( *REQUESTER )
             return
             enddo
       endselect
    
    /* +
       Wait up to an hour for job completion... +
    */
    
       rcvmsg   msgq( QGPL/CHKSBMJOB ) +
                  msgtype( *COMP ) +
                  wait( 3600 ) +
                  rmv( *NO ) +
                  keyvar( &msgkey ) +
                  msgdta( &msgdta ) msgid( &msgid )
    
       select
          when ( &msgid *eq 'CPF1241' )  do
             rmvmsg msgq( QGPL/CHKSBMJOB ) msgkey( &msgkey )
             sndmsg ( '2.' *bcat &msgid ) tousr( *REQUESTER )
             dmpclpgm
             enddo
          when ( &msgid *eq '       ' )  do
             sndmsg ( '3. No *COMP' ) tousr( *REQUESTER )
             enddo
          otherwise  do
             sndmsg ( '4.' *bcat &msgid ) tousr( *REQUESTER )
             dmpclpgm
             enddo
       endselect
    
       return
    
    endpgm
    The code is a simple test program. It submits a simple job and waits for it to complete. The submitted job just does a DLYJOB for 30 seconds.   The first thing after submitting the job is to extract the submitted job's name. That's often info that is needed. After that, it just waits until the job ends. It gets the signal in the form of a CPF1241 message. Once it receives it, the program ends.   So it just shows how to receive the message telling the name of the job and the message saying that it ended. I have no idea what you want to do at either of those points.   The code might be more than you need or less. Significant changes would likely be in the parameters for the RCVMSG commands and the code paths in the SELECT groups.   The first RCVMSG wants to get the latest *COMP message in the program's message queue. It currently gets the only *COMP message, but there's no way to predict if other *COMP messages were previously placed on this program's messae queue. You might choose to use slightly different RCVMSG parms or loop to test for the *COMP message with the latest timestamp. (But reading details of how *COMP messages are received from the queue might be helpful.)   You should note that both RCVMSG commands specify RMV(*NO) and that RMVMSG commands are run later along specific code paths. You might choose to do it differently. Generally, when I receive messages and handle them, I also remove them. I often don't know if I can handle them at the moment they're received, so I decide later whether to remove or not.   A couple DMPCLPGM and various SNDMSG commands should help track which paths are taken. Those can all be deleted of course. Together with debug, it should be very clear what happened during any test run that you migh make.   The QGPL/CHKSBMJOB message queue is created to help with testing. You could create a new one for every job. Message queues can be created and deleted; and they aren't very big, growing to a maximum of only 16MB when full. And these shouldn't need more than a single message or so. They can be deleted as soon as the *COMP is received. Downside is a small overhead of creating and possibly authorizing a permanent object. Just make sure it's linked to the SBMJOB MSGQ() parameter.   There might be one or two details I'm forgetting. They can be covered later if needed. Compile the code, and call the program a few times. Start a fresh session, submit a couple jobs manually before calling the program to see what interferes, if anything. Get a feel for what happens, and it should clear up soon.   Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    Well, sorry about the formatting. The PGM statement looks fine, but the rest lost its formatting. It's a little easier to read with useful indenting. It should compile and run, though.   Copy/paste into Notepad, map a drive to your IFS /home directory, save it there, then run CPYFRMSTMF to put it into a source member.   Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    I pasted a cleaner copy at http://pastebin.com/gWLHwJ9D to make it easier. That copy should last for a month.   Tom
    125,585 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