Command reference / CL
RCVMSG
Receive Message
Used by a program to receive a message previously sent to a message queue. It can receive from a job or program message queue tied to a call stack entry, from the external *EXT queue, or from a named or nonprogram queue such as QSYSOPR or a user profile queue. The program can receive from its own call stack entry or from another one. The message and its attributes are copied into the CL variables named by KEYVAR through DTACCSID. Messages can be selected by type, by reference key, or both. The program can remove the message or leave it as an old message. If the queue is not allocated to the job, the command allocates it for the duration of its processing. For an unhandled exception message, the program chooses whether this command handles the exception.
Allowed environments: *BPGM, *IPGM, *BREXX, *IREXX.
Use within a CL program.
Positional parameters: 5.
Parameters
PGMQ
Call stack entry message queue
Specifies the call stack entry message queue to receive from: the *EXT queue, or the queue of a program or ILE procedure call stack entry. If values are given, MSGQ(*PGMQ) is allowed.
Suggested / special values:
*EXT
*EXT- Receives from the job's external message queue, used to communicate with the external requester such as a display station user.
*SAME- Element 1: the queue belongs to the program or procedure named in element 2.
*PRV- Element 1: the queue belongs to the caller of the program or procedure named in element 2.
*- Element 2, element 1: the OPM program or ILE procedure running this command.
*NONE- No ILE module (element 2) or program (element 3) qualifier is provided.
Elements in order
Relationship
Relationship
Allowed values:
*SAME, *PRV
Call stack entry identifier
Call stack entry identifier
Elements in order
Call stack entry
Call stack entry
Suggested / special values:
*
Module
Module
Suggested / special values:
*NONE
Bound program
Bound program
Suggested / special values:
*NONE
MSGQ
Message queue
Specifies a message queue, other than a program message queue, to receive from. If a queue name is given, PGMQ cannot be specified.
Suggested / special values:
*PGMQ
*PGMQ- Receives only from the program message queue named in PGMQ.
*LIBL- Searches all libraries in the thread's library list until the first match.
*CURLIB- Uses the job's current library. If none is set, QGPL is used.
Qualified parts (object, then library; write LIBRARY/OBJECT)
Message queue
Message queue
Library
Library
Suggested / special values:
*LIBL, *CURLIB
MSGTYPE
Message type
Specifies the type of message the program receives.
Allowed values:
*ANY, *NEXT, *PRV, *INFO, *INQ, *RPY, *FIRST, *COPY, *COMP, *DIAG, *EXCP, *RQS, *LAST, *NXTJLMSG, *PRVJLMSG
*ANY- Any type except a sender's copy. Use *COPY to receive a sender's copy.
*NEXT- The message after the one identified by MSGKEY. Blanks are returned if none exists.
*PRV- The message before the one identified by MSGKEY.
*INFO- An informational message.
*INQ- An inquiry message.
*RPY- A reply to an inquiry this program sent.
*FIRST- The first message currently on the queue.
*COPY- A copy of a previously sent inquiry. The queue must match the RPYMSGQ used when the inquiry was sent.
*COMP- A completion message, from a program message queue only. Reports the status of work requested of another program.
*DIAG- A diagnostic message, from a program message queue only. Reports errors found in input or in processing.
*EXCP- An exception message (escape, notify, or status), received last in first out.
*RQS- A request message, from a program message queue only.
*LAST- The last message currently on the queue.
*NXTJLMSG- The job log message after the specified key. Can also reach messages on inactive program queues.
*PRVJLMSG- The job log message before the specified key. Can also reach messages on inactive program queues.
MSGKEY
Message key
Specifies the reference key of the message to receive. The variable must be a 4-character CL variable.
Suggested / special values:
*NONE, *TOP
*NONE- No message reference key is specified.
*TOP- The top of the queue. Can be used only with MSGTYPE(*NEXT).
WAIT
Wait time
Specifies, in seconds, how long to wait for a message of the specified type if none is on the queue. When the time passes, the CL variables are filled with blanks, or zeros for decimal variables.
Suggested / special values:
*MAX
*MAX- Waits indefinitely for the message.
RMV
Remove message
Specifies whether the received message is removed from the queue. For an unhandled exception, it also controls whether this command handles the exception.
Allowed values:
*YES, *NO, *KEEPEXCP
*YES- The message is removed. An unhandled exception is handled by this command.
*NO- The message is left on the queue as an old message. An unhandled exception is handled by this command.
*KEEPEXCP- An unhandled exception stays unhandled and the message stays as a new message. Otherwise the message is left as an old message.
CCSID
Coded character set ID
Suggested / special values:
*JOB, *HEX
RJTDFTRPY
Reject default reply
Allowed values:
*NOALWRJT, *ALWRJT
KEYVAR
CL var for KEYVAR (4)
Names the 4-character CL variable that receives the message reference key of the received message, which then becomes an old message. The key can be used later in MSGKEY.
MSG
CL var for 1st level text
Names the CL character variable that receives the message text, with substitution data inserted. For a reply, it receives the reply text.
MSGLEN
CL var for MSGLEN (5 0)
SECLVL
CL var for 2nd level text
SECLVLLEN
CL var for SECLVLLEN (5 0)
MSGDTA
CL var for msg data
MSGDTALEN
CL var for MSGDTALEN (5 0)
MSGID
CL var for MSGID (7)
Names the CL variable (at least 7 characters) that receives the message ID. Returned blank for immediate messages.
SEV
CL var for SEV (2 0)
Names the 2-position decimal variable that receives the message severity. Not returned for immediate messages.
SENDER
CL var for SENDER (80)
SENDERFMT
Sender format
Allowed values:
*SHORT, *LONG
RTNTYPE
CL var for RTNTYPE (2)
ALROPT
CL var for ALROPT (9)
MSGF
CL var for MSGF (10)
MSGFLIB
CL var for MSGFLIB (10)
SNDMSGFLIB
CL var for SNDMSGFLIB (10)
TXTCCSID
CL var for text CCSID (5 0)
DTACCSID
CL var for data CCSID (5 0)
Examples
RCVMSG MSGQ(SMITH) MSGKEY(&KEY) MSG(&WORK)
Receives the message with the reference key in &KEY from queue SMITH and copies its text into &WORK.
RCVMSG MSGQ(INV) WAIT(120) MSG(&WORK)
Receives a new message from queue INV into &WORK, waiting up to 120 seconds if none is present.
Generated from os/cl/catalog/RCVMSG.json and os/cl/help/RCVMSG.json.