ILE COBOL Programmer's Guide

Processing Relative Files

An ILE COBOL relative file is a file to be processed by a relative record number. To process a file by relative record number, you must specify ORGANIZATION IS RELATIVE in the SELECT statement for the file. A relative file can be accessed sequentially, randomly by record number, or dynamically. An ILE COBOL relative file cannot have a keyed access path.

To write Standard COBOL programs that access a relative file, you must create the file with certain characteristics. Table 24 lists these characteristics and what controls them.

Table 24. Characteristics of Relative Files that are Accessible to Standard COBOL Programs

Characteristic Control
The file must be a physical file.1 Create the file using the CRTPF CL command.
The file cannot be a shared file. Specify SHARE(*NO) on the CRTPF CL command.
No key can be specified for the file. Do not include any line with K in position 17 in the Data Description Specifications (DDS) of the file.
A starting position for retrieving records cannot be specified. Do not issue the OVRDBF CL command with the POSITION parameter.
Select/omit level keywords cannot be used for the file. Do not include any line with S or O in position 17 in the file DDS. Do not specify the COMP, RANGE, VALUES, or ALL keywords.
Records in the file cannot be reused. Specify REUSEDLT(*NO) on the CRTPF CL command.
Records in the file cannot contain NULL fields. Do not specify the ALWNULL keyword in the file DDS.
Note:

1  A logical file whose members are based on one physical file can be used as an ILE COBOL relative file.

The OPEN, READ, WRITE, START, REWRITE, DELETE, and CLOSE statements are used to access data that is stored in a relative file. Refer to the WebSphere Development Studio: ILE COBOL Reference for a description of each of these statements. The START statement applies only to files that are opened for INPUT or I-O and are accessed sequentially or dynamically.

For relative files that are accessed sequentially, the SELECT clause KEY phrase is ignored except for the START statement. If the KEY phrase is not specified on the START statement, the RELATIVE KEY phrase in the SELECT clause is used and KEY IS EQUAL is assumed.

For relative files that are accessed randomly or dynamically, the SELECT clause RELATIVE KEY phrase is used.

The NEXT phrase can be specified only for the READ statement for a file with SEQUENTIAL or DYNAMIC access mode. If NEXT is specified, the SELECT clause KEY phrase is ignored. The RELATIVE KEY data item is updated with the relative record number for files with sequential access on READ operations.

All physical database files that are opened for OUTPUT are cleared. Database files with RELATIVE organization, and with dynamic or random access mode, are also initialized with deleted records. Lengthy delays in OPEN OUTPUT processing are normal for extremely large relative files (over 1 000 000 records) that are accessed in dynamic or random access mode because the files are being initialized with deleted records. The length of time it takes to open a file with initialization depends on the number of records in the file.

When the first OPEN statement for the file is not OPEN OUTPUT, relative files should be cleared and initialized with deleted records before they are used. The RECORDS parameter of the INZPFM command must specify *DLT. Overrides are applied when the clear and initialize operations are processed by ILE COBOL, but not when they are processed with CL commands. For more information, see the discussion of the CLRPFM and INZPFM commands in the CL and APIs section of the Programming category in the iSeries 400 Information Center at this Web site -http://publib.boulder.ibm.com/pubs/html/as400/infocenter.htm.

New relative files opened for OUTPUT in sequential access mode are treated differently. Table 25 summarizes conditions affecting them.

Table 25. Initialization of Relative Output Files

File Access and CL Specifications Conditions at Opening Time Conditions at Closing Time   File Boundary
Sequential *INZDLT   Records not written are initialized.1 All increments.
Sequential *INZDLT *NOMAX size   CLOSE succeeds.1 File status is 0Q.2 Up to boundary of records written.
Sequential *NOINZDLT     Up to boundary of records written.
Random or dynamic Records are initialized. File is open.   All increments.
Random or dynamic *NOMAX size OPEN fails. File status is 9Q.3   File is empty.

Notes:

  1. Lengthy delays are normal when there remains an extremely large number of records (over 1 000 000) to be initialized to deleted records when the CLOSE statement runs.

  2. To extend a file boundary beyond the current number of records, but remaining within the file size, use the INZPFM command to add deleted records before processing the file. You need to do this if you receive a file status of 0Q, and you still want to add more records to the file. Any attempt to extend a relative file beyond its current size results in a boundary violation.

  3. To recover from a file status of 9Q, use the CHGPF command as described in the associated run-time message text.

For an ILE COBOL file with an organization of RELATIVE, the Reorganize Physical File Member (RGZPFM) CL command can:

In addition, a Change Physical File (CHGPF) CL command bearing the REUSEDLT option can change the order of retrieved or written records when the file is operated on sequentially, because it allows the reuse of deleted records.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]