CL400 MONMSG - skill-at/AS-400-Training GitHub Wiki

Monitor Message (MONMSG) command is used to monitor escape, notify, and status messages sent to the program message queue of the program in which the command is used. Other message types (completion, diagnostic, etc.) cannot be monitored.

When the MONMSG command is compiled in a control language (CL) program, it establishes a monitor for the arrival of the specified messages. The command monitors the messages for the condition specified by the comparison data given in the command. If a message meeting the conditions arrives on the message queue, the CL command specified on the MONMSG command is processed.

Up to 1000 MONMSG commands can be specified in a program to monitor the arrival of messages for specific conditions or for a group of conditions. Specific message identifiers or generic message identifiers can be monitored.

The MONMSG command can be coded following most commands in a CL program or ILE CL procedure. A MONMSG command that is not placed at the beginning of the program applies only to the immediately preceding command; this is called a command-level MONMSG command. The command-level MONMSG command monitors only messages sent by the previous command. If the message sent by that command meets the conditions specified in the MONMSG command, the action specified in the same MONMSG command is taken. As many as 100 MONMSG commands, coded immediately after a command, can monitor the messages sent by that command.

Program level MONMSG MONMSG specified after declare commands or after PGM command in case no declare commands is called program level MONMSG command. They monitor messages sent by all of the commands in the program (maximum of 100). This is called a program-level MONMSG command. If any message sent by any command in the program meets the conditions specified in any one of the program-level MONMSG commands, the corresponding action specified in the same command is taken. For **program level MONMSG only GOTO command can be specified for execution **.

Restrictions: This command is valid only in a CL program or ILE CL procedure. It can be coded after the last declare command (if declare commands are used), following the PGM command that begins the program, or it can be coded following any command allowed in a CL program or ILE CL procedure, except for the following: DO, DOWHILE, DOUNTIL, DOFOR, ELSE, ENDDO, SELECT, WHEN, OTHERWISE, ENDSELECT, ENDPGM, CALLSUBR, SUBR, RTNSUBR, ENDSUBR, GOTO, IF, or RETURN. Note that if another program sends a message that is monitored by this command, a return cannot be made to that program.

Escape Messages: Escape messages are sent to tell your procedure or program of an error condition that forced the sender to end. By monitoring for escape messages, you can take corrective actions or clean up and end your procedure or program.

Status or Notify Messages: Status and notify messages are sent to tell your procedure or program of an abnormal condition that is not serious enough for the sender to end. By monitoring for status or notify messages, your procedure or program can detect this condition and not allow the function to continue