Receiving Messages and Their Replies
From: Mark Read To: All
I was wondering if anyone could help me with the Receive Message (RCVMSG) command. I have set up a CL program with the following command:
RCVMSG MSGQ(&MSGQ) + MSGTYPE(*NEXT) MSGKEY(*TOP) + MSG(&MSGTXT) SENDER(&MSGSNDR)
This CL program is called from another program that will print the message data that is passed back via the parameters. Here's the problem that I'm having: if an inquiry message is in the message queue, I cannot seem to get the reply information.
For example, if the MSGQ parameter has a value of QSYSOPR, I would want to see the message text and the reply that our operators gave each message. According to the manual and IBM, it seems like replies are only available if the message is a program message rather than a normal message queue. Any ideas on how to retrieve the reply value? I looked in QUSRTOOL, the Retrieve Message (RTVMSG) command, etc., and had no luck. The Display Message (DSPMSG) command doesn't have an outfile option either.
From: Ernie Malaga To: Mark Read
Here's what I've been able to find out. All you want to do is possible, provided that the message queue is not allocated to another job. In order to use the RCVMSG command, the message queue must not have an *EXCL lock. This means that user profile message queues and display station message queues cannot be processed the way you want. QSYSOPR is a user profile message queue, and as such is allocated with *EXCL when QSYSOPR signs on.
For any other message queue, you can use the code in 2.
For any other message queue, you can use the code in Figure 2.
The first RCVMSG command gets the first message in the message queue. RMV(*NO) guarantees that the message won't be removed from the message queue, but simply read. KEYVAR(&MSGKEY) retrieves the key to the message just read into &MSGKEY, a four-character variable.
MSG(&MSGTXT) retrieves the text of the message into &MSGTXT, which can be of the length you want.
A loop (LOOP:) is then entered. The first RCVMSG of the LOOP attempts to receive the reply to a message if it was an *INQ message (&MSGTYPE = '05'). The RCVMSG retrieves the reply to the first message, if there is one, since we're specifying MSGTYPE(*RPY) and MSGKEY (&MSGKEY). This is so because both the original inquiry message and its reply message have the same key. Again, RMV(*NO) leaves the message in the queue and MSG(&RPYMSG) gets the reply text into &RPYTXT.
If a reply is found, &RPYTXT will contain the reply; otherwise, &RPYTXT will be blank.
Too bad this cannot be done on QSYSOPR or the like (unless QSYS-OPR is not signed on, which may be unlikely in many installations).
TechTalk: Receiving Messages and Their Replies
Figure 2 Receiving An *INQ Message and Its Reply
DCL VAR(&MSGTYPE) TYPE(*CHAR) LEN(2) DCL VAR(&MSGKEY) TYPE(*CHAR) LEN(4) DCL VAR(&MSGTXT) TYPE(*CHAR) LEN(80) DCL VAR(&RPYTXT) TYPE(*CHAR) LEN(80) RCVMSG MSGQ(...) MSGTYPE(*NEXT) MSGKEY(*TOP) RMV(*NO) + KEYVAR(&MSGKEY) MSG(&MSGTXT) RTNTYPE(&MSGTYPE) LOOP: + IF COND(&MSGTYPE *EQ '05') THEN(DO) RCVMSG MSGQ(...) MSGTYPE(*RPY) MSGKEY(&MSGKEY) + RMV(*NO) MSG(&RPYTXT) MONMSG MSGID(CPF2410) GOTO CMDLBL(ENDLOOP) ENDDO RCVMSG MSGQ(...) MSGTYPE(*NEXT) MSGKEY(&MSGKEY) + RMV(*NO) KEYVAR(&MSGKEY) MSG(&MSGTXT) RTNTYPE(&MSGTYPE) MONMSG MSGID(CPF2410) EXEC(GOTO CMDLBL(ENDLOOP)) Goto cmdlbl(loop) ENDLOOP: /* &MSGTXT will contain *INQ message if one exists in the message queue.*/ /* &RPYTXT will contain reply data if a reply was given. */