Receive messages into a CL procedure or program

You can use the Receive Message (RCVMSG) command to obtain a message from a message queue for your procedure or program. This topic includes general information on receiving messages and the details on receiving request messages and request processing programs.

Messages can be received in the following ways:

To receive a message, you can specify:

In the following sample Receive Message (RCVMSG) command, a message is obtained from message queue INVN in the QGPL library. The message text received is placed in the variable &MSG. *ANY is the default value on the MSGTYPE parameter.

RCVMSG MSGQ(QGPL/INVN) MSGTYPE(*ANY) MSG(&MSG)

When working with the call stack entry message queue of an ILE procedure written in a language other than CL, it is possible to receive an exception message (Escape or Notify) when the exception is not yet handled. The Receive Message (RCVMSG) command can be used to both receive a message and indicate to the system that the exception has been handled.

This can be controlled by using the RMV keyword. If *NO is specified for this keyword, the exception is handled and the message is left on the message queue as an old message. If *KEEPEXCP is specified, the exception is not handled and the message is left on the message queue as a new message. If *YES is specified, the exception message is handled and the message is removed from the message queue.

The RTNTYPE keyword can be used to determine if the message received is an exception message, and if so, whether the exception has been handled.

Related tasks
Remove messages from a message queue