Opening QSAM files

Before a program can use any READ, WRITE, or REWRITE statements to process records in a file, it must first open the file by using an OPEN statement.

An OPEN statement works if both of the following conditions are true:

  • The file is available or has been dynamically allocated.
  • The fixed file attributes coded in the ddname definition or the data-set label for the file match the attributes coded for that file in the SELECT clause and FD entry.

    Mismatches in the file-organization attributes, code set, maximum record size, or record format (fixed or variable) result in file status code 39, and the failure of the OPEN statement. Mismatches in maximum record size and record format are not errors when opening files in the z/OS® UNIX file system.

    For fixed-length QSAM files, if you code RECORD CONTAINS 0 in the FD entry, the record size attributes are not in conflict. The record size is taken from the DD statement or the data-set label, and the OPEN statement is successful.

Code CLOSE WITH LOCK so that the file cannot be opened again while the program is running.

Use the REVERSED option of the OPEN statement to process tape files in reverse order. The file is positioned at the end, and READ statements read the data records in reverse order, starting with the last record. The REVERSED option is supported only for files that have fixed-length records.

Related references  
OPEN statement (Enterprise COBOL for z/OS Language Reference)