>>-TRAPMSG(-+--------+-)---------------------------------------><
'-option-'
TRAPMSG
returns the value ON or OFF, which indicates whether or not REXX messages
(i.e. messages of the form IRX.....) or CLIST error messages from
CLISTs invoked by REXX are permitted to be trapped by the OUTTRAP
function. If TRAPMSG is invoked with a null operand, the current TRAPMSG
setting is returned, and the TRAPMSG setting is left unchanged.
With
TRAPMSG(OFF), the default, any REXX messages issued by execs or host
commands invoked by a REXX exec are always issued to the screen or
to the output stream, even if OUTTRAP is active in the exec. TRAPMSG(ON)
allows this to be changed so that such messages can be trapped. The
valid values for option are:
- OFF
- Sets the current TRAPMSG status to OFF and returns the previous
status. The default OFF indicates that REXX messages (IRX.....) and
CLIST error messages issued by an REXX exec, CLIST or host command
invoked by REXX will not be trapped in the currently active OUTTRAP
variable, if any. They will go to the output stream or terminal.
- ON
- Sets the current TRAPMSG status to ON and returns the previous
status. ON indicates that REXX messages (IRX.....) and CLIST error
messages issued by any REXX exec, CLIST or host command invoked by
REXX will be trapped in the currently active OUTTRAP variable, if
any. The exec can then examine the trapped error message.
Using TRAPMSG you can tell REXX that, when OUTTRAP
is also active, that any REXX messages or CLIST error messages that
would have otherwise been ignored by OUTTRAP and always written to
the screen or to the output stream are now permitted to be trapped
in the exec's active OUTTRAP variable.
TRAPMSG(ON) can be used to enable your exec to capture, in
an OUTTRAP variable, messages issued by a REXX exec, CLIST, or host
command invoked from REXX, if those messages are issued as PUTLINE
messages with the INFOR or DATA operands. Refer to the OUTTRAP function
for a description of the kinds of output that can or cannot be trapped
by OUTTRAP.
Examples:
Here are some examples:
- A REXX exec invokes execio without allocating the indd file. EXECIO
will return RC=20 and an error message. By trapping the message with
OUTTRAP, the exec can decide what to do with the error.
This same
technique can be used to trap the IRX0250E message if execio were
to take an abend, like a space B37 abend.
msgtrapstat = TRAPMSG('ON') /* Save current status and set
TRAPMSG ON to allow REXX msgs to
be trapped */
outtrap_stat = OUTTRAP('line.') /* Enable outtrap */
/*****************************************************************/
/* Invoke the TSO host command, execio, and trap any error msgs */
/* it might issue. */
/*****************************************************************/
"execio 1 diskr indd (stem rec. finis"
if RC = 20 then /* If execio error occurred */
do i=1 to rec.0
say '==> ' rec.i /* Write any error msgs */
end
outtrap_stat = OUTTRAP('OFF') /* Disable outtrap */
msgtrapstat = TRAPMSG('OFF') /* Turn TRAPMSG off */
- A REXX exec turns on OUTTRAP and TRAPMSG and invokes a second
REXX exec. The second REXX exec gets an IRX0040I message due to an
invalid function call. Exec1 is able to trap the message issued from
exec2.
Note that if exec1 had made the bad TIME function call, it
could not have trapped the error message because a function message
is considered at the same level as the exec. This is similar to the
fact that an exec can use OUTTRAP to trap SAY statement output from
an exec that it invokes, but it cannot trap its own SAY output.
/* REXX - exec1 */
SIGNAL ON SYNTAX /* Trap syntax errors */
trapit = OUTTRAP('line.')
trapmsg_stat = TRAPMSG('ON')
continu = 'continu1' /* Set Retry label */
call exec2
continu1: /* Retry label */
do i=1 to line.0 /* Display any output trapped fronm exec2 */
if i=1 then say '---------- start of trapped output ---------'
say '==> ' line.i
if i=line.0 then say '---------- end of trapped output ---------'
end
trapit = OUTTRAP('OFF')
trapmsg_stat = TRAPMSG('OFF')
exit 0
SYNTAX: /* Syntax trap routine */
SIGNAL ON SYNTAX /* Reenable syntax trap */
Interpret SIGNAL continue /* Continue in mainline at retry label*/
/* REXX - exec2 */
say 'In exec2 ...'
time = TIME('P') /* Invalid time operand, get msg IRX0040I */
return time