Considerations When Writing Relative Files

For OUTPUT files, the WRITE statement causes the following actions:
  • If ACCESS IS SEQUENTIAL is specified:

    The first record released has relative record number 1, the second record released has relative record number 2, the third number 3, and so on.

    If the RELATIVE KEY is specified in the File-Control entry, the relative record number of the record just released is placed in the RELATIVE KEY during execution of the WRITE statement.

  • If ACCESS IS RANDOM or ACCESS IS DYNAMIC is specified, the RELATIVE KEY must contain the desired relative record number for this record before the WRITE statement is issued. When the WRITE statement is executed, this record is placed at the specified relative record number position in the file.

For files opened in I-O mode, either ACCESS IS RANDOM or ACCESS IS DYNAMIC must be specified; the WRITE statement inserts new records into the file. The RELATIVE KEY must contain the desired relative record number for this record before the WRITE statement is issued. When the WRITE statement is executed, this record is placed at the specified relative record number position in the file.

For a physical file that does not allow the DELETE operation on records (for example, using the CRTPF with the ALWDLT(*NO) parameter), the update operation on records must be allowed (that is, CRTPF with the ALWUPD(*YES) parameter).