MainframeSupports
tip week 32/2003:

You can do a lot of different things using PL/1. Among those things is the ability to read almost any kind of files using the same technique. This technique does not support VSAM LDS which is used for DB2 datasets. I haven't tried VSAM ESDS or RRDS, but I am pretty confident that it will work. Anything else works as input and therefore it can manage spanned records which is used by SMF.

The program looks like this:

/* PLI - read almost any dataset */
readany: PROC OPTIONS(MAIN);

DCL sysprint FILE PRINT;
DCL anyfile FILE RECORD SEQUENTIAL;
DCL anyfile_data CHAR(32767) VAR;
DCL anyfile_eof CHAR(1);

ON ENDFILE(anyfile) anyfile_eof = 'Y';
anyfile_eof = 'N';
OPEN FILE(anyfile);
READ FILE(anyfile) INTO(anyfile_data);
DO WHILE(anyfile_eof = 'N');
  PUT SKIP FILE(sysprint) LIST(anyfile_data);
  READ FILE(anyfile) INTO(anyfile_data);
END;
CLOSE FILE(anyfile);

END readany;

The trick is the input file declaration and most important that data is read into a CHAR varying. If the record length is more than 32767 the program will fail, but I don't think any file types supports records longer than 32767, at least not yet. You can read LOAD modules and if you forget the member name while reading a PDS, you will instead read through the directory blocks.

In my example the program writes the contens of the records read to SYSPRINT. It is very hard to distinguish the records written from each other as soon as LRECL on input records exceeds LRECL on SYSPRINT. Here you can improve the program by adding some formatting to output, maybe a nice little hex dump. And of course you can process the data read, if you know their format. Another possible improvement is to limit the number of records to read.

Previous tip in english        Sidste danske tip        Tip list