OUTTRAP versus MSG function when trapping or suppressing output
TPUT and WTOs are not affected by MSG and OUTTRAP. MSG and OUTTRAP only affect messages that are issued by PUTLINE / PUTGET. Some PUTLINE messages might be suppressed by MSG('OFF') or might be trapped by OUTTRAP. PUTGET mode messages are generally not affected by the MSG setting, but some might be trapped by OUTTRAP, such as those for ACCOUNT or EDIT, and so on.
MSG('ON'|'OFF') affects only the display of Informational messages. Informational Message refers to a message that is issued by PUTLINE with the INFO keyword indicating that the message is an informational message. It is not always obvious from the message itself whether the message qualifies because you might not know how it was issued. But generally, TSO Command error messages are issued as INFO messages. However, most REXX messages, output from SAY statements, and TRACE output is usually issued as PUTLINE DATA output, therefore, MSG('OFF') would have no effect.
OUTTRAP can trap both INFO and DATA type of PUTLINE output. For example, the output from the "PROFILE LIST" is IKJ56688I, which can be suppressed by MSG('OFF') or can be trapped by OUTTRAP.
OUTTRAP cannot be used to trap REXX error message output that occurs during interpretation of the exec, or TRACE output or any IRXxxx message output that is issued by the interpreter for the executing exec that issued OUTTRAP. Also, OUTTRAP cannot trap SAY output from within the exec that issued OUTTRAP. However, if exec1 invokes exec2 (as a cmd of subroutine) and exec 2 issues SAY output, or exec2 generates TRACE output, the calling exec can trap that information. In addition, if an error occurs in exec2 causing the exec to issue an IRXxxx error message, that error can usually be trapped by the calling exec if TRAPMSG('ON') was set by exec1 before exec2 was invoked. Also, when a REXX exec issues a REXX command like EXECIO, or invokes another REXX function, IRXxxx messages that are issued from the command of function can usually be trapped if TRAPMSG('ON') was activated in the calling exec.
PUTLINE DATA output from some commands, such as "LISTA ST HI" can be trapped by OUTTRAP, but they cannot be suppressed by MSG('OFF'), since these output lines are usually issued as PUTLINE DATA lines.
In some cases, data can either be suppressed by MSG('OFF') or trapped by OUTTRAP. For example, the output IKJ56688I from "PROFILE LIST" can be either suppressed or trapped. However, if MSG('OFF') and OUTTRAP are both active, the message is seen by MSG('OFF') processing and suppressed before it can be seen and trapped by OUTTRAP.
Certain other output might be issued as WTO/WTP messages to the terminal. PROFILE NOWTPMSG can be used to suppress certain WTP/WTO type output.
Generally speaking, REXX OUTTRAP corresponds to CLIST &SYSOUTTRAP, and MSG('ON'/'OFF') corresponds to CLIST &SYSMSG (for example, CONTROL MSG/NOMSG). For more information about &SYSOUTTRAP and &SYSMSG usage, see z/OS TSO/E CLISTs.
If you have an exec that invokes an unknown command, IKJ56500I COMMAND XXXXXXXX NOT FOUND is issued. REXX also issues RC(-3) indicating that the command was not found. The IKJ56500I can be suppressed by MSG('OFF') but cannot be trapped by OUTTRAP.