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. |
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
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, 2005. All Rights Reserved.