Variable length records are only supported for database files associated with device type DISK.
You specify the Format 2 RECORD clause with the FD entry of the file to define the maximum and minimum record lengths for the file.
A simple file description entry in the Data Division that describes a sequential file with variable length records looks as follows:
FILE SECTION. FD sequential-file-name RECORD IS VARYING IN SIZE FROM integer-6 TO integer-7 DEPENDING ON data-name-1. 01 minimum-sized-record. 05 minimum-sized-element PIC X(integer-6). 01 maximum-sized-record. 05 maximum-sized-element PIC X(integer-7).
·
·
·
WORKING-STORAGE SECTION. 77 data-name-1 PIC 9(5).
·
·
·
The minimum record size of any record in the file is defined by integer-6. The maximum record size of any record in the file is defined by integer-7. Do not create record descriptions for the file that contain a record length that is less than that specified by integer-6 nor a record length that is greater than that specified by integer-7. If any record descriptions break this rule, then a compile time error message is issued by the ILE COBOL compiler. The ILE COBOL compiler also issues a compile time error message when none of the record descriptions contain a record length that is as long as integer-7.
For indexed files that contain variable length records, the prime record key must be contained within the first 'n' character positions of the record, where 'n' is the minimum record size specified for the file. When processing the FD entry, the ILE COBOL compiler will check that any RECORD KEY falls within the fixed part of the record. If any key violates this rule, an error message is issued.
The following conditions must be met for the OPEN statement to be successfully performed on a database file with variable length records:
If any of the above conditions are not satisfied, an error message will be generated, file status 39 will be returned, and the open operation will fail.
If an open operation is attempted on a database file with SHARE(*YES) which is already open but with a different record length than the current open operation, an error message will be generated and file status 90 will be returned.
When a READ, WRITE, or REWRITE statement is performed on a variable length record, the size of that record is defined by the contents of data-name-1.
Refer to the Format 2 RECORD clause in the WebSphere Development Studio: ILE COBOL Reference for a further description of how variable length records are handled.
You use the READ statement to read a variable length record from a database file. If the READ operation is successful then data-name-1, if specified, will hold the number of the character positions of the record just read. If the READ operation is unsuccessful then data-name-1, will hold the value it had before the READ operation was attempted.
When you specify the INTO phrase in the READ statement, the number of character positions in the current record that participate as the sending item in the implicit MOVE statement is determined by
When the READ statement is performed, if the number of character positions in the record that is read is less than the minimum record length specified by the record description entries for the file, the portion of the record area that is to the right of the last valid character read is filled with blanks. If the number of characters positions in the record that is read is greater than the maximum record length specified by the record description entries for the file, the record is truncated on the right to the maximum record size specified in the record description entries. A file status of 04 is returned when a record is read whose length falls outside the minimum or maximum record lengths defined in the RECORD clause in the file description entry for the file.
You use the WRITE or REWRITE statements to write a variable length record to a database file. You specify the length of the record to write in data-name-1. If you do not specify data-name-1, the length of the record to write is determined as follows:
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.