MainframeSupports
tip week 35/2008:

How do you find out if a dataset exists on the mainframe. My guess is that you use DSLIST in ISPF (also known as menu item 3.4). If you then needed to find a dataset from a program I am pretty sure you hav coded a REXX and made calls to the ISPF services that performs the same functionality as DSLIST does. Maybe your need was just to find out wheteher a given dataset was already cataloged or not. In this case you have probably used the SYSDSN function and maybe you sometimes use LISTCAT to perform any of the above.

Actually there is a service in MVS called CSI (stands for Catalog Service Interface) which you may call from almost any programming language and is able to create lists of datasets and find individual datasets. My friend Johnny Mossin made me aware of CSI. Probably some of you already know CSI, but without Johnny I would never have discovered it. The advantage of CSI is that you avoid using ISPF services and you may also use CSI from other languages than REXX. By using CSI it is possible to retrieve all information hidden in the MVS catalog structure (that is a lot) and last but not least it runs extremely fast.

Unfortunately the interface to CSI is very hard to use, especially if you want to retrieve the many different data about a dataset. I will give you two examples on how to use CSI, one from PL/I and one from REXX. Both examples perform exactly the same function which is to retrieve the name of the volume where a specific dataset is located. This is very practical if you need to find out wheteher a dataset is migrated or not because CSI does not issue any HSM recall. In PL/I it looks like this:

dataset_volume: PROC(dsname) RETURNS(CHAR(6));

DCL dsname CHAR(44) VAR;
DCL iggcsi00 EXT ENTRY OPTIONS(ASM INTER RETCODE);
DCL csi_reason CHAR(4);
DCL 1 csi_input
  , 2 csifiltk CHAR(44)
  , 2 csicatnm CHAR(44)
  , 2 csiresnm CHAR(44)
  , 2 csidtyps CHAR(16)
  , 2 csiopts
  , 3 csicldi CHAR(1)
  , 3 csiresum CHAR(1)
  , 3 csis1cat CHAR(1)
  , 3 csioptns CHAR(1)
  , 2 csinumen FIXED BIN(15)
  , 2 csifldnm CHAR(8)
  ;
DCL 1 csi_output
  , 2 csiusrln FIXED BIN(31)
  , 2 csireqln FIXED BIN(31)
  , 2 csiusdln FIXED BIN(31)
  , 2 csinumfd FIXED BIN(15)
  , 2 csicflg CHAR(1)
  , 2 csictype CHAR(1)
  , 2 csicname CHAR(44)
  , 2 csicretn CHAR(4)
  , 2 csieflg CHAR(1)
  , 2 csietype CHAR(1)
  , 2 csiename CHAR(44)
  , 2 csitotln FIXED BIN(15)
  , 2 csifill CHAR(2)
  , 2 csilenf1 FIXED BIN(15)
  , 2 csivolser CHAR(6)
  , 2 csimore CHAR(1000)
  ;

csi_reason = '';
csi_input = '';
csi_input.csifiltk = dsname;
csi_input.csinumen = 1;
csi_input.csifldnm = 'VOLSER';
csi_output = '';
csi_output.csiusrln = stg(csi_output);

CALL iggcsi00(csi_reason, csi_input, csi_output);
IF pliretv() ^= 0
THEN
  RETURN('CSIerr');
ELSE
  RETURN(csi_output.csivolser);

END dataset_volume;

And in REXX it looks like this:

dataset_volume:
ARG dsname

csireas = left(' ', 4)
csiinp = left(dsname, 44)!!left(' ',108)!!d2c(1,2)!!left('VOLSER',8)
csioutp = d2c(1024,4)!!left(' ',1020)

ADDRESS LINKPGM 'IGGCSI00 csireas csiinp csioutp'
IF RC = 0
THEN
  volser = substr(csioutp, 117, 6)
ELSE
  volser = 'CSIerr'
RETURN volser

In the PL/I function I have used the names from the CSI manual. I have not used any fields names in the REXX function, because REXX does not support structures. If the dataset name does not exist in the MVS catalog the volume serial variable will contain spaces and if it is migrated it will contain MIGRAT.

CSI only issues return codes not equal to zero if something went very wrong. The output area provided to CSI must be at least 1024 bytes long and the length of the output area must be present in the first four bytes in binary format. If you do not allocate storage in your program for the length provided in the first four bytes your storage may be destroyed or you may provoke a 0C4 abend. The same things may happen if you forget to put a reasonable value into the first four bytes.

You may use wildcards in the input dataset name. Then CSI will start returning all the dataset names with the requested information which matches your wildcard. Such a list of dataset information is returned in a special format described in appendix B in the manual Managing Catalogs. In this appendix you will find all the information IBM provides regarding CSI.

Previous tip in english        Sidste danske tip        Tip list