MAINFRAME > Tips & Techniques > Application Development

Some more REXX and TSO functions

Use REXX to determine data set types with TSO function


Editor’s Note: This is the final part of a series of articles in which Technical Editor Michael Cairns has provided a beginner’s guide to the REXX* programming language on z/OS*.

 

In the final primer in the REXX programming language you’ll get back to actually writing code, rather than dealing with environmental requirements, and add some logic to the REXX exec you’ve been working on.

It would be useful if the grep program could tell the difference between a Sequential or Partitioned data set, and act appropriately. So, for a Partitioned data set, it would make sense to have the REXX ask for the member name to search, perhaps even support a wildcard for member name matches. For Sequential data sets the behavior would essentially remain unchanged.

How to Discover Data Set Types

There is more than one method to determine the type of data set you’re searching. In this example, you’ll first use the REXX Time Sharing Option (TSO) external function LISTDSI to determine the type, and then use the TSO command DSLIST to retrieve the list of members, should the dataset turn out to be Partitioned Organization (PO).

Of course, it’s possible the user has entered a member name for you to parse in error, and the data set is really Physical Sequential (PS). To test for this, the first few lines of code then become:

/* REXX this is a REXX program */
parse UPPER arg dsn search
member = ''
parse var dsn dataset '(' member ')'
dataset = strip(dataset,'B',"'")

You now have two variables with which to work, data set and member. The following code would be inserted after the ADDRESS TSO, and prior to allocating the input data set:

cmdrc = LISTDSI(“’”dataset”’” DIRECTORY)
say cmdrc
say SYSDSORG
say SYSMEMBERS

Note the use of single quotes, surrounded by double quotes, in order to generate a fully qualified data set name for the LISTDSI function.

The variable ‘x’ contains the LISTDSI return code, and of course this should be checked for validity prior to any further processing.

The SYSDSORG and SYSMEMBERS are amongst the many variables populated by the call to LISTDSI. If the data set was sequential, then SYSMEMBERS is zero; otherwise, it contains a count of the members in the partitioned data set (PDS). In our scenario SYSDSORG is expected to contain either PS or PO, although other values are available.

Now you know what you’re dealing with, you can add some logic to the code for each scenario. In the case of a PDS, it would be nice to ask the user what he or she wanted to do if a member name or mask wasn’t already specified. You have to deal with member or member mask being both specified on the command line call to grep, and those unspecified until the user is prompted.

 

if SYSMEMBERS Â= 0 & member = '' then do /* PDS and no member passed */
say 'You have entered a PDS and no member name - would you like to:'
say '1) process all members - just hit enter'
say '2) process a member - please enter member name'
say '3) process a range of like named members - please enter a mask',
'followed by an asterisk such as: MEM*'
parse UPPER PULL member /* at this point we have a */
end /* member/mask or a blank */

Note the six embedded white-space characters in option three. These help the message display neatly on an 80-column screen.

If the DSORG is partitioned, you’ll need to parse the output of the LISTDS. The output from a LISTDS command looks something like this:

IBMUSER.TEST.REXX
--RECFM-LRECL-BLKSIZE-DSORG
FB 80 27920 PO
--VOLUMES--
TIVOLI
--MEMBERS--
MEM1
MEM2
MEMBER3
MEMBER4
 

You can use the following code to retrieve the list of members from the output above:

See Code Sample 1

This code reads the output, trapped in the variable ‘trap.i’, searching for the string ‘—MEMBERS—’ Once found, it starts keeping a list of the members until the end of the output is reached.

 

 

Michael Cairns works for IBM as a technical specialist in the Tivoli zSecure range of software. Michael can be reached at mike.cairns@au1.ibm.com.



Like what you just read? To receive technical tips and articles directly in your inbox twice per month, sign up for the EXTRA e-newsletter here.


comments powered by Disqus

Advertisement

Advertisement

2019 Solutions Edition

A Comprehensive Online Buyer's Guide to Solutions, Services and Education.

A Beginner's Guide to the REXX Programming Language on z/OS

Reading and Writing Files in the REXX programming language on z/OS.

MAINFRAME > TIPS & TECHNIQUES > APPLICATION DEVELOPMENT

Application Management is Important to the Entire Process

MAINFRAME > TIPS & TECHNIQUES > APPLICATION DEVELOPMENT

Application Testing: Giving Users What They Need

IBM Systems Magazine Subscribe Box Read Now Link Subscribe Now Link iPad App Google Play Store
Mainframe News Sign Up Today! Past News Letters