Question & Answer
Information about opening and closing non-VSAM data sets in the manual z/OS DFSMS: Using Data Sets (Document Number SC26-7410-06), in the non VSAM section, under the title 'Factors to Consider when Allocating Direct Access Data Sets':
When the system allocates a new SMS data set with DSORG=PS or no DSORG, the access methods treat the data set as being null, that is, having no data. A program can read the data set before data has been written in it. This means the first GET or first CHECK for a READ causes the EODAD routine to be called.
For data sets other than system-managed with DSORG=PS or null, the program receives unpredictable results such as reading residual data from a prior user, getting an I/O error, or getting an ABEND. Reading residual data can cause your program to appear to run correctly but you can get unexpected output from the residual data.
You can use one of the following methods to make the data set appear null:
1. At allocation time, specify a primary allocation value of zero; such as SPACE=(TRK,(0,10)) or SPACE=(CYL,(0,50)). This technique does not work with a VIO data set because creation includes the secondary space amount.
2. After allocation time, put an end-of-file mark at the beginning the data set, by running a program that opens the data set for output and closes it without writing anything.
Note that this only occurs in releases before z/OS 1.11. From the release announcement for z/OS 1.11:
In z/OS V1.11, DFSMSdfp™ processing is changed to indicate end-of-file (EOF) during the allocation of data sets on DASD that are not SMS-managed and have either sequential or an undefined data set organization. This makes this processing for both SMS-managed and non-SMS-managed data sets consistent to make it unnecessary to open data sets solely to indicate EOF, and to help prevent programs from reading old data when a data set is read immediately after being allocated.
14 November 2019