Skip to content

SND MSG

Daniel Long edited this page Sep 29, 2026 · 4 revisions

SND-MSG

SND-MSG sends a message. The message type is one of *INFO (the default), *DIAG, *COMP, *STATUS, *NOTIFY or *ESCAPE. IBM i writes the others to the job log; OpenRPG has no job log, so it prints them to stderr, prefixed with their type. *ESCAPE behaves as on IBM i: it is an error, sent to a call-stack entry.

Syntax

SND-MSG *INFO 'Informational message';
SND-MSG *DIAG 'Diagnostic detail';
SND-MSG *COMP 'Processing complete';

// Bare form — defaults to *INFO
SND-MSG 'Something happened';

// Variable message
DCL-S msg VARCHAR(100);
msg = 'Row count: ' + %CHAR(rowCount);
SND-MSG *DIAG msg;

The type is written directly after SND-MSG. SND-MSG TYPE(*INFO) 'text' is rejected: IBM i reads TYPE as a variable name (RNF0203).

*ESCAPE

By default an *ESCAPE message goes to the caller of the procedure that sends it, as on IBM i: that procedure ends at once -- its own MONITOR and *PSSR do not see the message -- and in the caller it is an error with status 202, message CPF9898 (in the PSDS). This is how a procedure reports failure:

DCL-PROC checkQty;
  DCL-PI *N;
    qty INT(10) VALUE;
  END-PI;
  IF qty < 0;
    SND-MSG *ESCAPE 'Quantity cannot be negative';   // checkQty ends here
  ENDIF;
END-PROC;

MONITOR;
  checkQty(-1);
ON-ERROR;
  DSPLY ('Caught: ' + %CHAR(%STATUS));   // Caught: 202
ENDMON;

%TARGET(*SELF) sends it to the procedure itself instead, where its own MONITOR handles it, with status 9999. Sent from the main procedure to its caller, an *ESCAPE ends the program, printing its text. %TARGET does not change where the other message types go.

Clone this wiki locally