OUTTRAP
A REXX function that captures the output of TSO commands into a stem variable, so the exec can read it.
Also written OUTTRAP function, OUTTRAP('OFF'), trap command output
OUTTRAP lets a REXX exec read what a TSO command prints. Normally a command such as LISTCAT writes its output to the screen. With OUTTRAP switched on, the output goes into a stem variable instead.
The pattern is short. x = OUTTRAP('LINE.') starts capturing into the stem LINE. Then the exec runs the command, such as "LISTCAT LEVEL(ZBANK)". Then x = OUTTRAP('OFF') stops capturing. LINE.0 holds the number of lines captured, and LINE.1, LINE.2 and so on hold the lines themselves. The exec can then loop through them, for example with PARSE, to pick out dataset names.
This is the basis of many useful execs: run a command, capture the output, and act on it, such as listing every dataset under a high-level qualifier and checking each one.
OUTTRAP does not catch everything. Some commands write directly to the terminal in a way OUTTRAP cannot capture, and output from ISPF services is not trapped. If a stem stays empty, check whether that command's output can be trapped at all.
Where can I learn this hands-on?
Right here, at ZedBank. You take a junior job at a simulated bank and learn each part of the work by doing it, with Zed beside you. There's nothing to install.
Start at ZedBankRelated
- REXXA readable scripting language used across the mainframe for automation, tooling and quick one-off tasks.
- Stem variableREXX's array, a variable with a dot in its name used to hold a list such as the lines of a file.
- TSO commandA command typed at a TSO prompt or on an ISPF command line to ask the system to do something directly.
- REXX execA REXX program, stored as a member in a library and run by name from TSO or ISPF.
- EXECIOThe REXX command for reading records from a dataset, or writing records to one, under TSO.
- LISTCATA TSO command that lists what the catalog knows: dataset names and which catalog holds them.