About two and a half year ago I wrote a tip about how you can validate the existence of a dataset from COBOL, PL/I or REXX by using CSI (Catalog Subsystem Interface). I also mentioned that CSI may be used to create lists of dataset names. I have used quite a lot of time to extent the pretty simple code from the tip in order to make it create a list. Therefore I thought that you might be interested in the result, because it is rather difficult to create a list.
I have chosen to write the example in COBOL. I hope you are able to translate it into PL/I or REXX if you prefer one of these languages. I will start with the required definitions in working-storage:
And here is a piece of COBOL code that creates and prints the list on SYSOUT:
In the example I have chosen to print all dataset names matching the filter SYS1.*. It is important to notice that * is the wildcard for exactly one qualifier while ** is the wildcard for zero to many qualifiers. I have also added some code for error handling. As you will notice it requires special coding to detect an invalid filter. On the other hand I found out that it is hard to provoke this error. A blank filter is considered invalid while other combinations that I consired being invalid were accepted by CSI.
In working-storage I have allocated 108000 bytes to the dataset list. If the filter matches more dataset names than there is room for in 108000 bytes CSI sets the field CSIRESUM to Y and the call is repeated in order to retrieve the remaining dataset names. Note the test of whether variable CSIRESNM has changed value since last call. This condition may be true if your filter matches a GDG dataset with a lot of generations as each generation is not treated as a new dataset name, but as a part of a single GDG entry. Because of this you must ensure that variable CSIDATAAREA can contain the dataset names of all generations once. If not you may end up in a loop. I have not tested this situation, so I am not sure whether the return-code continues to be zero or not.
You will quite fast discover that CSI is an extremely fast interface that is able to produce long lists of dataset in no time. Actually it is much faster than both DSLIST and LISTCAT. These two programs of course uses CSI, but they also do a lot of other stuff which slows them down. In the manual (use link in earlier tip) it is described how you can retrieve a lot of other information than just the volume serial as in this tip. If you want to select other information than the volume serial you must carefully study how data is built in the dataset list and change the working-storage variables and the coding accordingly. It is not simple, but I wish you good luck.