Commands used to send messages from a CL program

The Send Program Message (SNDPGMMSG) command or the Send User Message (SNDUSRMSG) command is used to send a message from a CL procedure or program.

Using the SNDPGMMSG command, you can send the following types of messages:

  • Informational
  • Inquiry
  • Completion
  • Diagnostic
  • Request
  • Escape
  • Status
  • Notify

You can send messages from a CL procedure or program to the following types of queues:

  • External message queue of the requester of the job
  • Call message queue of a program or procedure called by the job
  • System operator message queue
  • Workstation message queue
  • User message queue

To send a message from a procedure or program, you can specify the following on the SNDPGMMSG command:

  • Message identifier or an immediate message. The message identifier is the name of the message description for a predefined message.
  • Message file. The name of the message file containing the message description when a predefined message is sent.
  • Message data fields. If a predefined message is sent, these fields contain the values for the substitution variables in the message. The format of each field must be described in the message description. If an immediate message is sent, there are no message data fields.
  • Message queue or user to receive the message.
  • Message type. The following indicates which types of messages can be sent to which types of queues (V = valid).
Table 1. Valid message types for message queue types
Message type Message queue type
External Call QSYSOPR Workstation User
Informational V V V V V
Inquiry V   V V V
Completion V V V V V
Diagnostic V V V V V
Request V V      
Escape   V      
Status V V      
Notify V V      
  • Coded character set identifier (CCSID). Specifies the coded character set identifier (CCSID) that the supplied message or message data is in.
  • Reply message queue. The name of the message queue that receives the reply to an inquiry message. By default, the reply is sent to the call message queue of the procedure or program that sent the inquiry message.
  • Key variable name. The name of the CL variable to contain the message reference key for a message.

To send the message created in Example: Describing a message, you would use the following command:


SNDPGMMSG   MSGID(USR4310) MSGF(QGPL/USRMSG) +
            MSGDTA(&CUSNO) TOPGMQ(*EXT) +
            MSGTYPE(*INFO)

The substitution variable for the message is the customer number. Because the customer number varies, you cannot specify the exact customer number in the message. Instead, declare a CL variable in the CL procedure or program for the customer number (&CUSNO). Then specify this variable as the message data field. When the message is sent, the current value of the variable is passed in the message:


Customer number 35500 not found

In addition, you do not always know which display station is using the procedure or program, so you cannot specify the exact display station message queue that the message is to be sent to (TOMSGQ parameter); therefore, you specify the external message queue *EXT on the TOPGMQ parameter.