Break Handling Message Queues

A break-handling program can be attached to a message-queue such that whenever a message arrives in the queue, the program is executed.

This is particularly useful if you need to break into a long running interactive job (i.e the screen is "Input Inhibited" and where the Attention Key is not enabled). Option 5 off of the System request menu allows you to send a message to any queue. You can create a message queue (in QTEMP say) and attach a break-handling program that assumes the message is a command and executes it using QCMDEXC.



I typically create a message-queue call "M" in QTEMP during the intial program and attach the break-handling program MPGM to it.Therefore to execute a Work with Active Jobs during a long running interactive job I enter the following key sequence:

         {SysReq}5wrkactjob m

 

The following code retrieves the message, assumes that it is an AS/400 command and proceeds to execute it using QCMDEXC. (This same technique is used to execute commands on other people's work-stations!).

QCLSRC source:                MPGM

                  PGM              PARM(&MSGQ &MSGL &MSGK)
                  DCL               VAR(&MSGQ) TYPE(*CHAR) LEN(10)
                  DCL               VAR(&MSGL) TYPE(*CHAR) LEN(10)
                  DCL               VAR(&MSGK) TYPE(*CHAR) LEN(4)


                  DCL                VAR(&MSG) TYPE(*CHAR) LEN(200)
                  DCL                VAR(&MSGDTA) TYPE(*CHAR) LEN(200)
                  DCL                VAR(&MSGID) TYPE(*CHAR) LEN(7)
                  DCL                VAR(&MSGF) TYPE(*CHAR) LEN(10)
                  DCL                VAR(&MSGL) TYPE(*CHAR) LEN(10)
                  MONMSG        MSGID(CPF0000) EXEC(GOTO CMDLBL(ERROR))


                  RCVMSG          MSGQ(&MSGQ) MSGKEY(&MSGK) MSG(&MSG)
                  SNDPGMMSG   MSGID(CPF9898) MSGF(QCPFMSG) +
                                        MSGDTA('Executing:-' || &MSG) +
                                          TOPGMQ(*EXT) MSGTYPE(*STATUS)
                  CALL                 PGM(QCMDEXC) PARM(&MSG 200)
                  RETUR N


ERROR:
  MSGD:      RCVMSG          MSGTYPE(*DIAG) MSG(&MSG) MSGDTA(&MSGDTA) +
                                         MSGID(&MSGID) MSGF(&MSGF) MSGFLIB(&MSGL)
                  IF                    COND(&MSGID *NE ' ') THEN(DO)
                 SNDPGMMSG    MSGID(&MSGID) MSGF(&MSGL/&MSGF) +
                                        MSGDTA(&MSGDTA) MSGTYPE(*DIAG)
                 GOTO               CMDLBL(MSGD)
                 ENDDO
  MSGE:      RCVMSG           MSGTYPE(*EXCP) MSG(&MSG) MSGDTA(&MSGDTA) +
                                         MSGID(&MSGID) MSGF(&MSGF) MSGFLIB(&MSGL)
                 IF                     COND(&MSGID *NE ' ') THEN(SNDPGMMSG +
                                        MSGID(&MSGID) MSGF(&MSGL/&MSGF) +
                                        MSGDTA(&MSGDTA) MSGTYPE(*ESCAPE))
                 ENDPGM

Insert the following code into your initial program to set up the
interrupt feature.

/* Create Local interrupt */
CRTMSGQ MSGQ(QTEMP/M)
MONMSG MSGID(CPF0000)
CHGMSGQ MSGQ(QTEMP/M) DLVRY(*BREAK) PGM(*LIBL/MPGM)

Home | Software Solutions | iSeries Security | Tips & Techniques | Consulting | About us | Contact Us



Sentinex Inc.
379 Hamilton Drive
Stewartsville, NJ, 08886

Telephone: (800) 822 1004
Outside USA: (908) 213 8650
FAX: (908) 213 8652
e-Mail: info@sentinex.com
Member of PartnerWorld for Developers
IBM is a registered trademark of IBM Corporation.