Published at 1/16/2025

A REXX OUTTRAP Secret

A REXX OUTTRAP Secret (don't tell anyone)

When using REXX, under z/OS TSO, the ability to trap the results of TSO commands, including other REXX execs, can be very helpful. BUT one thing that can not be trapped are messages generated by the say REXX command.

Well, that isn't completely true.

OUTTRAP is able to capture messages generated using the putline service of TSO, typically used in assembler programs. Unfortunately the say REXX command, and many other TSO commands, use the tput service which is not trappable.

Or is it.

It seems that if you call a REXX exec from a REXX exec while outtrap is active that it can actually trap the messages generated by the say command.

Sample REXX to Demonstrate

Driving REXX

This REXX code will trap the output of the TSO LISTD command into a REXX stem and at the same time add to the trapped stem some comments.

 /* rexx */
 call outtrap 't.'
 x = sayit('Calling LISTD')
 x = sayit(' ')
 "listd 'sys1.parmlib'"
 x = sayit(' ')
 x = sayit('LISTD Completed.')
 call outtrap 'off'
 do i = 1 to t.0
   say t.i
 end

The subroutine sayit is another REXX exec that can be found in the allocated SYSEXEC or SYSPROC libraries.

The SAYIT Subroutine

The sayit subroutine is very simple. It takes wherever is passed to it and then echos it using the REXX say command:

/* rexx */
parse arg option
say option
exit 0

Sample Results

This is what you will see, obviosly with your own system's specific information:

Calling LISTD
                            
SYS1.PARMLIB
--RECFM-LRECL-BLKSIZE-DSORG 
  FB    80    27920   PO
--VOLUMES--
  Z31CAT
                            
LISTD Completed.

Share on social media

Facebook share buttonReddit share buttonThreads share button