Receiving a message from a program or procedure that has ended

Occasionally, there is a need to receive messages from the job log that are sent to a call message queue that is no longer active.

For example, PGMA calls PGMB and PGMB sends a diagnostic message to itself and an escape message to PGMA. PGMA can easily receive the escape message that was sent to it, but sometimes it is necessary to also receive the diagnostic message. Because the diagnostic is on a call message queue that is no longer active, the message must be received by using a message reference key. This can be done, but it takes more work than one simple receive message command.

The following considerations are important in understanding how this works:

  • If the Receive Message (RCVMSG) command (or QMHRCVPM API) is coded to receive a message by key from its own call message queue, it will receive the message with that key (if it still exists) from the job log, regardless of what call message queue the message was sent to or whether that procedure is active.
  • The message reference key for messages in the job log can be treated as a 4-byte unsigned integer that is incremented for each message sent (even though it is documented externally as a 4-character value).

The following steps are required to obtain a message from a program or procedure that has ended:

  1. Send a message (and optionally remove it) to obtain a starting message reference key.
  2. Run the function that will send the messages you are interested in.
  3. Send another message to obtain an ending message reference key.
  4. In a loop, increment the message reference key between the starting and ending message keys identified in steps 1 and 3 and receive the message for each key. There can be gaps in the message reference key so the CPF2410 exception from the receive message function must be handled. The gaps can occur from a message that have been deleted or from internal exception handling.