Receive Program Message (QMHRCVPM) API


  Required Parameter Group:


  Optional Parameter Group 1:


  Optional Parameter Group 2:


  Optional Parameter Group 3:


  Default Public Authority: *USE

  Threadsafe: Yes

The Receive Program Message (QMHRCVPM) API receives a message from a call message queue or external message queue and returns information describing the message.

To receive a message from nonprogram message queues, see Receive Nonprogram Message (QMHRCVM) API.

In a multithreaded job messages can be received from call message queues within the thread that calls this API, and messages sent from within the same thread can be received from the external message queue. Messages on call message queues in other threads or sent to the external message queue from other threads cannot be received.


Authorities and Locks

Message File Authority
*USE, if receiving a predefined message and the message file used when the message was sent was deleted and recreated.

Message File Library Authority
*EXECUTE, if receiving a predefined message and the message file used when the message was sent was deleted and recreated.


Required Parameter Group

Message information
OUTPUT; CHAR(*)

The variable that receives the information returned, in the format specified in the format name parameter, of the length specified in the length of message information parameter.

Length of message information
INPUT; BINARY(4)

The size of the area to contain the message information, in bytes. The minimum size is 8.

This parameter must specify the size of the variable you use for the message information parameter. If this parameter specifies a longer size, other parts of storage could be overwritten when the API returns the information.

The API returns as much information as it can fit in this length. If the available message information is longer, it is truncated. If the available message information is shorter, the unused output area is unchanged; whatever is already stored in that space remains there.

To determine how much information the API actually returns in response to this call, see the bytes returned field in the RCVM0100, RCVM0200, or RCVM0300 output. To determine how much information the API could return if space were available, see the bytes available field.

Format name
INPUT; CHAR(8)

The format to use for the message information. Specify one of these format names:


Call stack entry
INPUT; CHAR(*) or Pointer

The call stack entry from whose message queue messages are to be received, or the call stack entry to start counting from when using a value other than 0 for the call stack counter parameter. The call stack entry you specify must be in the call stack or you can specify the external message queue instead of a call stack entry.

You can specify a call stack entry by providing the name of the OPM program or ILE procedure running in the entry, by providing a pointer to the call stack entry, or by using one of the following special values:

If the call stack entry is to be identified by pointer, the pointer that is specified must address a valid call stack entry within the same job as the one the API is used in. Alternatively, the pointer can be set to Null. The pointer must be 16 byte aligned. The Optional Parameter Group 1 must be used and the Length of call stack entry parameter must be set to 16. In addition, the Optional Parameter Group 2 must also be used and the Call stack entry format parameter must be set to *PTR.

If the pointer provided is set to Null, this indicates that the call stack entry is the one in which the API is being used.

If the pointer does not address a valid call stack entry or is not a Null pointer, the error message CPF24C5 is sent to the user of the API.

The call stack entry can be a nested procedure name from 1 through 4096 characters in length. When specifying nested procedures, each procedure name must be separated by a colon, and the outermost procedure is identified first followed by the procedures it contains. The innermost procedure is the last procedure identified in the string.

The call stack entry can be a partial name. To specify a partial name, place three less-than signs (<<<) at the beginning of the call stack entry identifier, or place three greater-than signs (>>>) at the end of the call stack entry identifier, or place both the less-than signs and the greater-than signs at their respective ends of the call stack entry identifier. The value for the call stack entry excluding the less-than signs and the greater-than signs is used to search backward through the stack for the requested call stack entry name.

When searching for a partial call stack entry name:

  • If the less-than signs (<<<) are specified only at the beginning of the call stack entry name, the less-than signs are truncated and the remaining character string is right-justified. The remaining string is then compared to the current call stack entry on the call stack. The comparison starts at the end of the call stack entry name and backwardly compares the number of characters in the specified string.

  • If the greater-than signs (>>>) are specified only at the end of the call stack entry name, the greater-than signs are truncated. The remaining character string is compared to the current call stack entry on the call stack. The comparison starts at position 1 of the call stack entry name and compares the number of characters in the specified string.

  • If the less-than signs (<<<) are specified at the beginning of the call stack entry name and the greater-than signs (>>>) are specified at the end of the call stack entry name, both the less-than signs and the greater-than signs are truncated. The remaining characters are used to scan and to compare the entire length of the specified string and the current call stack entry on the call stack.

Note: If the optional parameters Length of to call stack entry and To call stack entry data type are not specified, this parameter is assumed to be CHAR(10).

Call stack counter
INPUT; BINARY(4)

A number identifying the location in the call stack of the call stack entry from whose message queue the messages are to be received. The number is relative to the call stack entry identified by the Call stack entry parameter. It indicates how many calls up the call stack the target entry is from the one identified by the Call stack entry parameter. Valid values follow:


Message type
INPUT; CHAR(10)

The type of the message being received. The message type and message key parameters work together. Depending on the message type, the key can be required, optional, or disallowed. For a list of valid message types and information about how they work with the message key parameter, see Message Types and Message Keys.

Message key
INPUT; CHAR(4)

The key to the message being received. The key is assigned by the command or API that sends the message.

What you can use for the message key parameter depends on what you use for the message type. For details, see Message Types and Message Keys.

If you are not receiving messages by key, use blanks for this parameter.

If you specify a key and the message queue does not contain a message with that key, an error is returned.

If you specify a key and the message queue does contain a message with that key, the API might or might not return a message. It never returns an error in this case. Whether or not the API returns a message depends on the value of the message type parameter. For example, if you specify the message type *PRV and there is no message before the message with the key, the API does not return a message. Because the key you specified is valid, the API does not return an error either.

You can receive the reply to a message through the key to the sender's copy of the message. If the reply is not available, no message is returned, and the API does not return an error.

When the message type is *NEXT, you can use *TOP for the message key to receive the next message after the last message received.

When the message type is *NEXT, *PRV, *NXTJLMSG, or *PRVJLMSG you can use hexadecimal zeros for the message key for the first receive operation to obtain a message key that can be specified on a subsequent receive operation.

If you know the message key of a message you want to receive, you can receive that message without regard to the call message queue containing the message. You can do this by specifying the key in this parameter, the special value '*' for the Call stack entry parameter and the value '0' for the call stack counter parameter. This is useful if the message was sent to a call stack entry that is no longer in the call stack.

Wait time
INPUT; BINARY(4)

The length of time to wait for the message to arrive in the queue so it can be received. Valid values follow:

If you specify a value of zero or above and the message does not arrive in the specified time, most fields in the RCVM0100, RCVM0200 or RCVM0300 output are unchanged. The bytes returned output field has a value of 8, and the bytes available output field has a value of 0. The remaining output fields are unchanged; they contain whatever was already stored in the space.

Message action
INPUT; CHAR(10)

The action to take after the message is received. Valid values follow:

For Integrated Language Environment® (ILE) programs, the message action also indicates if an exception message should be handled. If the message action is *OLD or *REMOVE, an exception is handled. If *SAME is specified, the exception is not handled.

Error code
I/O; CHAR(*)

The structure in which to return error information. For the format of the structure, see Error code parameter.


Optional Parameter Group 1

Length of call stack entry
INPUT; BINARY(4)

The length of the value for the call stack entry parameter. Valid values for this parameter are as follows:

  • 1 through 4096 if partial name indicators are not used.
  • 16 if the call stack entry parameter is a pointer.
  • 1 through 4102 if partial name indicators are used.

Note: The actual length of the call stack entry name cannot exceed 4096 characters. If this parameter is not used, the value for the call stack entry parameter is assumed to be 10 characters in length.

Call stack entry qualification
INPUT; CHAR(20)

The name of the module and the ILE program or service program to further qualify the procedure name specified by the Call stack entry parameter. The first 10 characters specify the module name, and the second 10 characters specify the ILE program or service program name. If this parameter is not used, only the Call stack entry parameter is used to determine the call stack entry. The following special value may be used:

If the call stack entry is to be identified by pointer, this parameter must still be passed to the API but both the module name and program name qualifiers must be specified as *NONE. When a pointer is used, the module and program name qualification is not applicable.

The module name and bound program name should be used only when identifying the call stack entry for an ILE procedure. When identifying the entry for an OPM program, the Optional Parameter Group 1 should either not be used or both the module name and bound program name should be specified as *NONE.


Optional Parameter Group 2

Call Stack entry data type
INPUT; CHAR(10)

Whether the value of the call stack entry parameter is a character string (a name or special value) or a pointer. Use one of the following special values:

If the above optional parameter is not specified, it is assumed that the value of the Call stack entry parameter is a character string.

Coded character set identifier
INPUT; BINARY(4)

The coded character set identifier (CCSID) that you want your message text and message data returned in. This applies to the text and the parts of the message data defined as a convertible character field (*CCHAR). For more information about *CCHAR fields, see the Add Message Description (ADDMSGD) Command. The following values are allowed:

If this parameter is not specified, 0 is used and messages are returned in the CCSID of the job.

Note: If an invalid CCSID conversion is detected during the receive function, the data is not converted before it is returned. The CCSID conversion status field should be checked to determine if an error occurred.

For more information about message handler and its use of CCSIDs, see CCSID support for messages.


Optional Parameter Group 3

Allow default reply rejection
INPUT; CHAR(10)

Removing an unanswered inquiry causes the default reply to be sent to the inquiry message. This value indicates whether a reply handling exit program will be allowed to reject a default reply that is sent as a result of using this function. A reply handling exit program can be registered via the system registration facility for exit point QIBM_QMH_REPLY_INQ. If this parameter is not specified, a value of *NO is used. This parameter is only applicable when *REMOVE is specified for the message action parameter. Valid values are:


Message Types and Message Keys

The message type and message key parameters work together. Depending on the message type, the key can be required, optional, or disallowed. The following table lists each message type you can specify, tells whether it requires a key, and gives other information about using that type.

When used without a key, most message types receive only new messages. When used with a key, most can receive old or new messages. Message types *FIRST, *LAST, *PRV (previous), *NEXT, *NXTJLMSG (next job log message), and *PRVJLMSG (previous job log message) always receive both old and new messages.

New messages are messages that have been sent to a queue and have not yet been received. Old messages are messages that have been received but have not yet been removed from the queue.

Messages of type *EXCP are received in last-in first-out (LIFO) order. Messages of all other types are received in first-in first-out (FIFO) order.

The following terms are used to describe the message key in the following table:

There are two cases where the message is not found and no error is returned. In both cases, the bytes returned field equals 8 and the bytes available field equals 0. The two cases are:

The message types you can specify in the QMHRCVPM API are:



RCVM0100 Format

The following table lists the fields returned in the RCVM0100 format. For more information about each item of information, see Field Descriptions.



RCVM0200 Format

The following table lists the fields returned in the RCVM0200 format. For more information about each item of information, see Field Descriptions.



RCVM0300 Format

The following table lists the fields returned in the RCVM0300 format. For more information about each item of information, see Field Descriptions.



Sender Information Format

The following table lists the fields for the sender information format of the RCVM0300 format. For more information about each item of information, see Field Descriptions.



Field Descriptions

The following field descriptions apply only when a message is received. If no message is found, only the bytes available and bytes returned fields contain new values. The remaining fields contain whatever information was already stored in the space allowed for the output.

Alert option. Whether and when an SNA alert is created and sent for the message. If a message is received, the value is one of the following:

For more information, see the Alerts Support Link to PDF manual.

Bytes available. The length of all available information that could be returned for the format. Bytes available can be greater than the length specified in the API's length of message information parameter. If it is greater, the information returned in the message information parameter is truncated to the length specified.

Bytes returned. The length of all information returned in the format. The value of the bytes returned field is always less than or equal to the length of the message information parameter. Also, it is always less than or equal to the bytes available. There is one exception to this. When you attempt to receive a message and the message is not found, the following occurs:

If the bytes returned value is less than the length specified in the length of message information parameter, the extra space in the message information parameter is unchanged.

CCSID conversion status indicator for data. The following values may be returned:

CCSID conversion status indicator for text. The following values may be returned:

CCSID of message and message help. The CCSID of the text in the message and message help fields is returned. The inserted replacement data may not be the same CCSID. Refer to the CCSID of the replacement data or impromptu message text field description for a more details.

If a conversion error occurs or the CCSID you requested the text to be converted to is 65535, the CCSID that the message description is stored in is returned. Otherwise, the CCSID you wanted your text converted to is returned. If you do not want the text converted before it is returned to you but you do want to know the CCSID that the message description is stored in specify 65535 on the Coded character set identifier parameter. The CCSID that the message description is stored in is returned in the CCSID of message and message help output field.

CCSID of replacement data or impromptu message text. The CCSID of the impromptu message text or replacement data is returned. If an impromptu message is received, this is the CCSID of the impromptu message text. When replacement data is received, this is the CCSID of the message data fields defined as convertible character (*CCHAR) in the message description. All other replacement data will not be converted before it is returned. If a conversion error occurs or if the CCSID you requested the data to be converted to is 65535, the CCSID of the data is returned. If message data is being returned and there is no *CCHAR replacement data, 65535 is returned. Otherwise, the CCSID you wanted the data converted to is returned.

Date sent. The date on which the message was sent, in CYYMMDD (century, year, month, day) format.

Displacement to long receiving procedure name. When the receiving type is 1 or 2, the offset to the long receiving procedure name, in bytes, from the beginning of the data returned in the sender information format. If there is not enough room to contain any of the long receiving procedure, this field is zero.

Displacement to long sending procedure name. When the sending type is 1 or 2, the offset to the long sending procedure name, in bytes, from the beginning of the data returned in the sender information format. If there is not enough room to contain any of the long sending procedure, this field is zero.

Displacement to long sending program name. The offset to the long sending program name, in bytes, from the beginning of the data returned in the sender information format. If there is not enough room to contain any of the long sending program, this field is zero.

Length (general information about the following length fields). These formats use two types of length fields, each related to a single variable length text field. (The variable length text fields return information to the caller.) The first type of length field is returned length; the second is available length. Returned length is the actual length of the text in the variable length text field. Available length is the length of the text before it is placed in the variable length text field. It is always greater than or equal to the returned length. If the available length equals the returned length, all the message information is returned. If the text is truncated when placed in the variable length field, the available length is greater than the returned length by the number of characters truncated.

Length of long receiving procedure name. For type 1 and 2, the length of the complete receiving procedure name, in bytes.

Length of long sending procedure name. For type 1 and 2, the length of the complete sending procedure name, in bytes.

Length of long sending program name. The length of the complete sending program name, in bytes.

Length of message available. The length of the available message text, in bytes. If an immediate message is received, the value of this field is zero.

Length of message help available. The length of the available message help information, in bytes. If an impromptu message is received, the value of this field is zero.

Length of message help returned. The length of the message help information, in bytes. If an impromptu message is received, the value of this field is zero.

Length of message returned. The length of the returned text of a predefined message, in bytes. If an impromptu message is received, the value of this field is zero.

Length of replacement data or impromptu message available. The length of the available impromptu message text or replacement data, in bytes. If the message identifier is not blank, this field contains the length of the available message data for a predefined message. If the message identifier is blank, this field contains the length of the available text of an impromptu message.

Length of replacement data or impromptu message returned. The length of the returned impromptu message text or replacement data, in bytes. If the message identifier is not blank, this field contains the length of the replacement data. If the message identifier is blank, this field contains the length of the impromptu message text.

Length of sender information available. The length, in bytes, of information available in the sender information format.

Length of sender information returned. The length, in bytes, of information returned in the sender information format.

Long receiving procedure name. For type 1 and 2, complete procedure name that received the message. A nested procedure name has each procedure name separated by a colon. The outermost procedure name is identified first followed by the procedures it contains. The innermost procedure is identified last in the string.

Long sending procedure name. For type 1 and 2, complete procedure name that sent the message. A nested procedure name has each procedure name separated by a colon. The outermost procedure name is identified first followed by the procedures it contains. The innermost procedure is identified last in the string.

Long sending program name. The program name that sent the message.

Message. The text of a predefined message. If an impromptu message is received, this field is blank.

The API can truncate the message to fit the available space. If truncation occurs in the middle of double-byte character set (DBCS) data, the API returns only complete DBCS characters. It ends the data with a DBCS shift-in character.

Message file library specified. The name of the library containing the message file, as specified in the call to this API. If you specify *CURLIB or *LIBL for the library when you send the message, that value is returned as the library here. For the actual library used when the message is sent, see the message file library used field.

Message file library used. The name of the library used to send the message. Because the library can contain override instructions, this is not necessarily the library in which the message actually resides.

Message file name. The name of the message file containing the message received.

Message help. The message help for the message received. If an immediate message is received, this field is blank.

The API can truncate the message help to fit the available space. If truncation occurs in the middle of double-byte character set (DBCS) data, the API returns only complete DBCS characters. It ends the data with a DBCS shift-in character.

Message identifier. The identifying code of the message received. If an immediate message is received, this field is blank.

Message key. The key to the message received. The key is assigned by the command or API that sends the message. If the message action parameter specifies *REMOVE, this field is blank.

Message severity. The severity of the message received. Possible values are 0 through 99. If the message being received is an immediate message, the message severity is not returned.

Message type. The message type of the message received. The possible values and their meanings are:

Microseconds. The microseconds part of the time sent.

Name of the procedure receiving the message. This field is blank if the message was received by an original program model (OPM) program.

Number of statement numbers or instruction numbers available for the receiving program or procedure. For OPM programs and nonoptimized procedures, this count is 1. For optimized procedures, this count can be greater than 1. In this case, each statement number represents a potential point at which the message could have been received. If the mapping table information is removed from the program, this field returns a count of zero and no statement numbers are available.

Number of statement numbers or instruction numbers available for the sending program or procedure. For OPM programs and nonoptimized procedures, this count is 1. For optimized procedures, this count can be greater than 1. In this case, each statement number represents a potential point at which the message could have been sent. If the mapping table information is removed from the program, this field returns a count of zero and no statement numbers are available.

Receiving module name. For type 1 and 2, the name of the module receiving the message.

Receiving procedure name. For type 1 and 2, the name of the procedure receiving the message. A nested procedure name has each procedure name separated by a colon. The outermost procedure name is identified first followed by the procedures it contains. The innermost procedure is identified last in the string.

Receiving program name. The name of the program receiving the message, or the Integrated Language Environment (ILE) program name that contains the procedure receiving the message.

Receiving program's statement number or instruction number. This field can contain up to three statement numbers or instruction numbers. When the receiving type is 1 or 2, the field contains statement numbers. When the receiving type is 0, this field contains an instruction number. Each statement number can be up to 10 characters in length. The instruction number is 4 characters in length. Each statement number or instruction number is left-justified in a 10-character partition of the 30-character field. The first statement number or instruction number is in the leftmost 10 characters and the third in the rightmost 10 characters. The unused parts of this field are set to blanks.

Receiving type. The type of program that received the message. Valid values follow:

Replacement data or impromptu message text. The values for substitution variables in a predefined message, or the text of an impromptu message. If the message identifier is not blank, this field contains message data. If the message identifier is blank, this field contains impromptu message text.

If this field contains message data that contains pointer data, each pointer must start on a 16-byte boundary. If you are running at security level 50, the pointer data is invalidated.

The API can truncate the data or text to fit the available space. If the field contains the text of an impromptu message and is truncated in the middle of double-byte character set (DBCS) data, the API returns only complete DBCS characters. It ends the data with a DBCS shift-in character. However, if the field contains data for a predefined message, the API does not check for DBCS data. This is because message data can contain pointers, and pointers can contain the same characters used to mark DBCS data.

Reserved. An ignored field.

Sending job. The name of the job in which the message being received was sent. Because the sending job also must be the receiving job for call message queues, this field is always blank.

Sending job's number. The job number of the job in which the message being received was sent. Because the sending job also must be the receiving job for call message queues, this field is always blank.

Sending job's user profile. The name of the user profile in the qualified job name of the job that sent the message being received. Because the sending job also must be the receiving job for call message queues, this field is always blank.

Sending module name. For type 1 and 2, the name of the module that contains the sending message.

Sending procedure name. For type 1, the name of the procedure sending the message. A nested procedure name has each procedure name separated by a colon. The outermost procedure name is identified first followed by the procedures it contains. The innermost procedure is identified last in the string.

Sending program name. The program name or ILE program name that contains the procedure sending the message. This field is blank if the sending type is 3.

Sending program's instruction number. The number of the program instruction that issued the command or called the API used to send the message being received.

Sending program's statement numbers or instruction numbers. This field can contain up to three statement numbers or an instruction number. When the sending type is 0 or 3, this field contains an instruction number. The instruction number is 4 characters in length of original program model (OPM) programs and 6 characters in length for System Licensed Internal Code (SLIC) programs. For all other sending types, this field contains statement numbers. Each statement number can be up to 10 characters in length. The instruction number is 4 characters in length. Each statement number or instruction number is left-justified in a 10-character partition of the 30-character field. The first statement number or instruction number is in the leftmost 10 characters and the third in the rightmost 10 characters. The unused parts of this field are set to blanks.

Sending type. The type of the sender (whether it is a program or procedure). Possible values and their meanings are as follow:

Sending user profile. The name of the user profile that the thread was running under when the message was sent.

Time sent. The time at which the message being received was sent, in HHMMSS (hour, minute, second) format.


Error Messages



API introduced: V2R1.1

[ Back to top | Message Handling APIs | APIs by category ]