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.

Type
*ELEM
Required
No
Case
Uppercase

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

Type
*CHAR
Required
No
Default
*SAME
Length
5
Case
Uppercase

Allowed values: *SAME, *PRV

Call stack entry identifier Call stack entry identifier

Type
*ELEM
Required
No
Case
Uppercase
Elements in order

Call stack entry Call stack entry

Type
*CHAR
Required
No
Default
*
Length
50
Case
Uppercase

Suggested / special values: *

Module Module

Type
*NAME
Required
No
Default
*NONE
Length
10
Case
Uppercase

Suggested / special values: *NONE

Bound program Bound program

Type
*NAME
Required
No
Default
*NONE
Length
10
Case
Uppercase

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.

Type
*QUAL
Required
No
Default
*PGMQ
Case
Uppercase

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

Type
*NAME
Required
No
Length
10
Case
Uppercase

Library Library

Type
*NAME
Required
No
Default
*LIBL
Length
10
Case
Uppercase

Suggested / special values: *LIBL, *CURLIB

MSGTYPE Message type

Specifies the type of message the program receives.

Type
*CHAR
Required
No
Default
*ANY
Length
9
Case
Uppercase

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.

Type
*CHAR
Required
No
Default
*NONE
Length
50
Case
Uppercase

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.

Type
*INT4
Required
No
Default
0
Case
Uppercase

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.

Type
*CHAR
Required
No
Default
*YES
Length
9
Case
Uppercase

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

Type
*UINT2
Required
No
Default
*JOB
Range
1 to 65535
Case
Uppercase

Suggested / special values: *JOB, *HEX

RJTDFTRPY Reject default reply

Type
*CHAR
Required
No
Default
*NOALWRJT
Length
9
Case
Uppercase

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.

Type
*CHAR
Required
No
Length
50
Case
Uppercase
Returns
CL variable

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.

Type
*CHAR
Required
No
Length
50
Case
Uppercase
Returns
CL variable

MSGLEN CL var for MSGLEN (5 0)

Type
*DEC
Required
No
Length
15
Case
Uppercase
Returns
CL variable

SECLVL CL var for 2nd level text

Type
*CHAR
Required
No
Length
50
Case
Uppercase
Returns
CL variable

SECLVLLEN CL var for SECLVLLEN (5 0)

Type
*DEC
Required
No
Length
15
Case
Uppercase
Returns
CL variable

MSGDTA CL var for msg data

Type
*CHAR
Required
No
Length
50
Case
Uppercase
Returns
CL variable

MSGDTALEN CL var for MSGDTALEN (5 0)

Type
*DEC
Required
No
Length
15
Case
Uppercase
Returns
CL variable

MSGID CL var for MSGID (7)

Names the CL variable (at least 7 characters) that receives the message ID. Returned blank for immediate messages.

Type
*CHAR
Required
No
Length
50
Case
Uppercase
Returns
CL variable

SEV CL var for SEV (2 0)

Names the 2-position decimal variable that receives the message severity. Not returned for immediate messages.

Type
*DEC
Required
No
Length
15
Case
Uppercase
Returns
CL variable

SENDER CL var for SENDER (80)

Type
*CHAR
Required
No
Length
50
Case
Uppercase
Returns
CL variable

SENDERFMT Sender format

Type
*CHAR
Required
No
Default
*SHORT
Length
6
Case
Uppercase

Allowed values: *SHORT, *LONG

RTNTYPE CL var for RTNTYPE (2)

Type
*CHAR
Required
No
Length
50
Case
Uppercase
Returns
CL variable

ALROPT CL var for ALROPT (9)

Type
*CHAR
Required
No
Length
50
Case
Uppercase
Returns
CL variable

MSGF CL var for MSGF (10)

Type
*CHAR
Required
No
Length
50
Case
Uppercase
Returns
CL variable

MSGFLIB CL var for MSGFLIB (10)

Type
*CHAR
Required
No
Length
50
Case
Uppercase
Returns
CL variable

SNDMSGFLIB CL var for SNDMSGFLIB (10)

Type
*CHAR
Required
No
Length
50
Case
Uppercase
Returns
CL variable

TXTCCSID CL var for text CCSID (5 0)

Type
*DEC
Required
No
Length
15
Case
Uppercase
Returns
CL variable

DTACCSID CL var for data CCSID (5 0)

Type
*DEC
Required
No
Length
15
Case
Uppercase
Returns
CL variable

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.

IBM command documentation

Generated from os/cl/catalog/RCVMSG.json and os/cl/help/RCVMSG.json.