Command reference / CL
MONMSG
Monitor Message
Monitors escape, notify, and status messages sent to the program message queue of the program containing the command; completion, diagnostic, and other message types cannot be monitored. A command-level MONMSG applies only to the immediately preceding command, while a program-level MONMSG placed at the start of the program applies to messages from all commands in the program (up to 100); a command-level MONMSG overrides a program-level one.
Allowed environments: *BPGM, *IPGM.
Use within a CL program.
Positional parameters: 3.
Restrictions
- Valid only in a CL program or ILE CL procedure.
- Can follow the last declare command, the PGM command, or most CL commands, but not DO, DOWHILE, DOUNTIL, DOFOR, ELSE, ENDDO, SELECT, WHEN, OTHERWISE, ENDSELECT, ENDPGM, CALLSUBR, SUBR, RTNSUBR, ENDSUBR, GOTO, IF, or RETURN.
- If another program sends a message monitored by this command, a return cannot be made to that program.
Parameters
MSGID
Message identifier
Specifies the message identifiers of one or more escape, notify, or status messages to be monitored by this command. Up to 50 specific or generic identifiers can be specified.
CMPDTA
Comparison data
Specifies comparison data used to decide whether a monitored message is acted on by this command. It is compared with the first part (up to 28 characters) of the message's substitution values.
Suggested / special values:
*NONE
*NONE- No comparison data is specified. If the message is from a monitored command and has the specified identifier, the EXEC action is taken.
EXEC
Command to execute
Specifies the CL command to be processed when a monitored message sent to the program's message queue meets the conditions specified in this command. If no command is specified, the message is ignored and control passes to the next command.
Examples
MONMSG MSGID(CPF0001 CPF1999) EXEC(GOTO EXIT2)
Placed at the start of a CL procedure, it monitors messages that any later command may send; on either message, control branches to the label EXIT2.
MONMSG MSGID(MCH1211) EXEC(CHGVAR VAR(&A) VALUE(1))
Follows a CHGVAR command and monitors only that command; when the division by zero sends MCH1211, the second CHGVAR sets &A to 1.
Generated from os/cl/catalog/MONMSG.json and os/cl/help/MONMSG.json.