× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I wrote:

> However, tomorrow I'll have a go at putting together something
> that should work a bit better and annotating it for you.

As promised here is some revised code with explanatory comments.

/*  Let's declare some variables we'll be using for message handling */

    DCL        VAR(&JOBNAME) TYPE(*CHAR) LEN(10)
    DCL        VAR(&JOBUSER) TYPE(*CHAR) LEN(10)
    DCL        VAR(&JOBNBR) TYPE(*CHAR) LEN(6)
    DCL        VAR(&SBMJOBQ) TYPE(*CHAR) LEN(6)
    DCL        VAR(&SBMJOBQLIB) TYPE(*CHAR) LEN(6)
    DCL        VAR(&MSGF) TYPE(*CHAR) LEN(10)
    DCL        VAR(&MSGFLIB) TYPE(*CHAR) LEN(10)
    DCL        VAR(&MSGID) TYPE(*CHAR) LEN(7)
    DCL        VAR(&MSGDTA) TYPE(*CHAR) LEN(80)

/*  We want to detect when the submitted job has finished. We need +
    a message queue to monitor. Let's use a dedicated queue named  +
    BACKUPMSGQ in QGPL. To make sure there are no unreceived       +
    messages in it already we'll clear it. If we fail to clear it  +
    we'll assume it doesn't exist and create it. If we can't create+
    it the program will bomb. This should be catered for in our    +
    global MONMSG and error handling routine.                      */

    CLRMSGQ    MSGQ(QGPL/BACKUPMSGQ)
    MONMSG     MSGID(CPF2357) EXEC(DO)
        CRTMSGQ    MSGQ(QGPL/BACKUPMSGQ) TEXT('Message queue +
                     for back-up completion messages')
        ENDDO

/*  Now we'll submit the job. In your case it's SAVCHGOBJ but for  +
    testing purposes let it be a DLYJOB command. Note the MSGQ     +
    parameter to route the completion message to the queue we are  +
    going to monitor.                                              */

    SBMJOB     CMD(DLYJOB DLY(10)) JOB(OURTEST) +
                 MSGQ(QGPL/BACKUPMSGQ)

/*  Now we'll get the ID details of the job we just submitted. You +
    may not need to do this now as we are not going to do a DSPJOB +
    on it any more. However it illustrates the technique so let's  +
    go for it anyway.                                              */

A_RCVMSG:
    RCVMSG     MSGTYPE(*COMP) MSGDTA(&MSGDTA) MSGID(&MSGID)

/*  The SBMJOB command will cause a CPC1221 completion message to +
    be sent to the program message queue.  We'll go for this      +
    message. We can't assume it's the only completion message so  +
    we'll loop until we find it.                                  */

    IF         COND(&MSGID *NE CPC1221) THEN(DO)
        GOTO       CMDLBL(A_RCVMSG)
        ENDDO

/*  Now we've got the CPC1221 we'll extract the job ID information+
    from the message data.                                        */

    CHGVAR     VAR(&JOBNAME) VALUE(%SST(&MSGDTA 1 10))
    CHGVAR     VAR(&JOBUSER) VALUE(%SST(&MSGDTA 11 10))
    CHGVAR     VAR(&JOBNBR) VALUE(%SST(&MSGDTA 21 6))
    CHGVAR     VAR(&SBMJOBQ) VALUE(%SST(&MSGDTA 27 10))
    CHGVAR     VAR(&SBMJOBQLIB) VALUE(%SST(&MSGDTA 37 10))

/*  Now we'll put our own message data together                   */

    CHGVAR     VAR(&MSGDTA) VALUE('Waiting for')
    CHGVAR     VAR(&MSGDTA) VALUE(&MSGDTA *BCAT &JOBNBR)
    CHGVAR     VAR(&MSGDTA) VALUE(&MSGDTA *TCAT '/')
    CHGVAR     VAR(&MSGDTA) VALUE(&MSGDTA *TCAT &JOBUSER)
    CHGVAR     VAR(&MSGDTA) VALUE(&MSGDTA *TCAT '/')
    CHGVAR     VAR(&MSGDTA) VALUE(&MSGDTA *TCAT &JOBNAME)
    CHGVAR     VAR(&MSGDTA) VALUE(&MSGDTA *BCAT 'to +
                 complete from')
    CHGVAR     VAR(&MSGDTA) VALUE(&MSGDTA *BCAT &SBMJOBQLIB)
    CHGVAR     VAR(&MSGDTA) VALUE(&MSGDTA *TCAT '/')
    CHGVAR     VAR(&MSGDTA) VALUE(&MSGDTA *TCAT &SBMJOBQ)

/*  We can now send a status message using our data with CPF9897  +
    which is a general purpose message kindly provided by IBM.    */

    SNDPGMMSG  MSGID(CPF9897) MSGF(QSYS/QCPFMSG) +
                 MSGDTA(&MSGDTA) TOPGMQ(*EXT) MSGTYPE(*STATUS)

/*  Here's where we wait for the submitted job to end. There is no+
    need to code a loop, we just use an infinite wait. If we were +
    not prepared to wait for ever we could use a different wait   +
    parameter. We would then test the message ID and if it was    +
    blank we would know that the wait had timed out and take some +
    action. Maybe we would send a warning message to a pager and  +
    loop back to the RCVMSG to carry on waiting.                  */

    RCVMSG     MSGQ(QGPL/BACKUPMSGQ) WAIT(*MAX) +
                 MSGDTA(&MSGDTA) MSGID(&MSGID) MSGF(&MSGF) +
                 MSGFLIB(&MSGFLIB)

/*  As we are not timing out in this instance we can assume that  +
    we have received the completion message for the submitted job.+
    We'll just resend that message back up the stack.             */

    SNDPGMMSG  MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) +
                 MSGDTA(&MSGDTA) MSGTYPE(*COMP)

As an aside I notice you're not saving access paths. While this will give
you a quicker save it will also give you a much longer restore. In most
situations the gain outweighs the pain if you save the access paths.

Dave...

"The sooner we get behind schedule, the more time we will have to make it
up." -- Anon Construction Superintendent

=======================================================
The opinions expressed in this communication are my own and do not
necessarily reflect those of my employer.



As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.