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 25 lists these characteristics and what controls them.
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 ILE COBOL for AS/400 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 Information Center at this Web site -http://www.ibm.com/eserver/iseries/infocenter.
New relative files opened for OUTPUT in sequential access mode are treated differently. Table 26 summarizes conditions affecting them.
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.
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.