Example 3 - Using the OUTTRAP Function
/******************************* REXX ******************************/
/* This exec lists datasets allocated to a ddname that is passed */
/* as an argument when the exec is invoked. It uses the OUTTRAP */
/* function to trap output from the LISTA STATUS command. It then */
/* loops through the output looking for a match to the input ddname*/
/* When match is found, the exec will SAY the name of all datasets */
/* allocated to that ddname. */
/* */
/* The LISTA STATUS command produces output of the form */
/* */
/* DATASET-NAME-ALLOCATED-TO-DDNAME */
/* DDNAME DISP */
/* */
/* In this output when the area for DDNAME is blank, then the data */
/* set is allocated to the previous DDNAME that was not blank. This*/
/* condition is one of the tests in the program below. */
/* */
/*******************************************************************/
ARG ddname .
x = OUTTRAP('ddlist.') /* start output trapping into DDLIST*/
"LISTA STATUS" /* issue the LISTA command */
x = OUTTRAP('OFF') /* turn off output trapping */
done = 'NO' /* initialize loop control variable */
DOi=1TOddlist.0 WHILE done = 'NO'
IF (words(ddlist.i) = 2) & ddname = word(ddlist.i,1) THEN
DO /* if there is a DDNAME & it matches*/
firstdataset=i-1 /*back up to first dataset name */
SAY ddlist.firstdataset /* Give the first dataset allocated */
DO j = i+1 TO ddlist.0 BY 2 WHILE done = 'NO'
next=j+1
IF (next <= ddlist.0) & (words(ddlist.next)\=1) THEN
done = 'YES' /* if we reach the end of the command
output, or the next DDNAME, we are
done */
ELSE
SAY ddlist.j /* Give the next dataset allocated */
END
END
END
If done = 'NO' then /* If the DDNAME is not allocated */
say "The DDNAME" ddname "is not allocated."
/* Then say so */
EXIT 0
Function Packages
A function package is a group of external routines (functions and subroutines) that
are accessed more quickly than external routines written in interpreted REXX.
Routines in a function package must be written in a programming language that
produces object code, which can be link-edited into a load module. The routine
must also support the system interface for function packages. Some programming
languages that meet these qualifications are assembler, COBOL, and PL/I.
There are three types of function packages.
Additional Examples
Chapter 10. Using TSO/E External Functions 133