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. For an example of a program that accesses and updates a consecutive data set, see Figure 14.
If you open the file for output, and wish to extend the data set by adding records at the end, you need not specify APPEND(Y) in the DD:ddname environment variable, since this is the default. If you specify APPEND(N), the data set is overwritten. If you open a file for updating, you can only update records in their existing sequence, and if you want to insert records, you must create a new data set. You cannot change the record length of an existing 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. Every record that is retrieved, however, need not be rewritten. A REWRITE statement always updates 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.
To access a data set, you must identify it to PL/I using the TITLE option of the OPEN statement or a DD:ddname environment variable.
Table 16 shows the statements and options for accessing and updating a consecutive data set.
When your application accesses an existing RECORD file, PL/I must obtain a record length value for that file. The value can come from one of the following sources:
PL/I uses a default record length value for an INPUT file when: