Once you create a consecutive data set, you can open the file that accesses it for sequential input, for sequential output, or, for data sets on direct access devices, for updating. See Figure 31 for an example of a program that accesses and updates a consecutive data set. If you open the file for output, and extend the data set by adding records at the end, you must specify DISP=MOD in the DD statement. If you do not, the data set will be overwritten. If you open a file for updating, you can update only records in their existing sequence, and if you want to insert records, you must create a new data set. Table 17 shows the statements and options for accessing and updating a consecutive data set.
When you access a consecutive data set by a SEQUENTIAL UPDATE file, you must retrieve a record with a READ statement before you can update it with a REWRITE statement; however, every record that is retrieved need not be rewritten. A REWRITE statement will always update the last record read.
Consider the following:
READ FILE(F) INTO(A);
.
.
.
READ FILE(F) INTO(B);
.
.
.
REWRITE FILE(F) FROM(A);
The REWRITE statement updates the record that was read by the second READ statement. The record that was read by the first statement cannot be rewritten after the second READ statement has been executed.
You cannot update a consecutive data set on magnetic tape except by adding records at the end. To replace or insert records, you must read the data set and write the updated records into a new data set.
You can read a consecutive data set on magnetic tape forward only. Reading backward is not supported.
To access a data set, you must identify it to the operating system in a DD statement. Table 21 summarizes the DD statement parameters needed to access a consecutive data set.
| Parameters | What you must state | When required |
|---|---|---|
|
DSNAME= DISP= |
Name of data set Disposition of data set |
Always |
| UNIT= or VOLUME=REF= | Input device | If data set not cataloged (all devices) |
| VOLUME=SER= | Volume serial number | If data set not cataloged (direct access) |
| DCB=(BLKSIZE= | Block size1 | If data set does not have standard labels |
|
Note:
1Or you could specify the
block size in your PL/I program by using the ENVIRONMENT attribute. |
||
The following paragraphs indicate the essential information you must include in the DD statement, and discuss some of the optional information you can supply. The discussions do not apply to data sets in the input stream.