What is the difference between SNDPGMMSG and SNDUSRMSG?

Both SNDPGMMSG and SNDUSRMSG are CL commands used to send messages in IBM i, but they serve different purposes and have distinct characteristics:

SNDPGMMSG (Send Program Message)

  • Purpose: Primarily used for communication within a program or between programs in the same call stack. It's often used for:
    • Status updates: Informing the calling program or the job log about the progress of a program.
    • Error handling: Sending escape messages to indicate that a program has encountered an error and needs to terminate.
    • Notifications: Sending notify messages about conditions that might require attention but don't necessarily cause termination.
  • Message Types: Supports a wider range of message types, including:
    • *STATUS
    • *ESCAPE
    • *NOTIFY
    • *COMPL (Completion)
    • *DIAG (Diagnostic)
  • Message Destination: Can send messages to:
    • The external message queue for the job (*EXT)
    • A specific message queue
    • The message queue of the calling program

SNDUSRMSG (Send User Message)

  • Purpose: Designed for communication with a user or system operator. It's typically used for:
    • Inquiry messages: Asking the user for input or confirmation.
    • Informational messages: Displaying information to the user.
  • Message Types: Generally used for:
    • *INQ (Inquiry)
    • *INFO (Informational)
    • *COMPL (Completion)
    • *DIAG (Diagnostic)
  • Message Destination: Can send messages to:
    • A specific user's message queue
    • The system operator's message queue
    • A display station

Key Differences Summarized:

Feature SNDPGMMSG SNDUSRMSG
Primary Use Intra-program/call stack communication User/operator communication
Message Types Wider range (status, escape, notify, etc.) Primarily inquiry and informational
Destination Job's external queue, specific queue, caller's queue User's queue, operator's queue, display station

 

In essence:

  • SNDPGMMSG is for internal program communication and error handling.
  • SNDUSRMSG is for interacting with users or the system operator.

Example:

If you want to display a message to the user asking for confirmation, you would use SNDUSRMSG with MSGTYPE(*INQ). If you want to send a message to the calling program indicating that a subroutine has completed successfully, you would use SNDPGMMSG with MSGTYPE(*COMPL).