Before you can read from or write to a file that is stored on a tape device, you must first open the file. You use the Format 1 OPEN statement to open the file. To read from a file stored on a tape device, you must open it in INPUT mode. To write to a file stored on a tape device, you must open it in OUTPUT or EXTEND mode. A file stored on a tape device cannot be opened in I-O mode. The following are examples of the OPEN statement.
OPEN INPUT sequential-file-name. OPEN OUTPUT sequential-file-name. OPEN EXTEND sequential-file-name.
You use the Format 1 READ statement to read a record from a sequential file stored on a tape device. The READ statement makes the next logical record from the file available to your ILE COBOL program. For a sequential multivolume file, if the end of volume is recognized during processing of the READ statement and the logical end of file has not been reached, the following actions are taken in the order listed:
Your ILE COBOL program will receive no indication that the above actions have occurred during the read operation.
You use the Format 1 WRITE statement to write a record to a sequential file stored on a tape device. For a sequential multivolume file, if the end of volume is recognized during processing of the WRITE statement, the following actions are taken in the order listed:
No indication that an end of volume condition has occurred is returned to your ILE COBOL program.
When you have finished using a file stored on a tape device, you must close it. Use the Format 1 CLOSE statement to close the file. Once you close the file, it cannot be processed any longer until it is opened again.
CLOSE sequential-file-name.
The CLOSE statement also gives you the option of rewinding and unloading the volume.
Ordinarily, when the CLOSE statement is performed on a tape file, the volume is rewound. However, if you want the current volume to be left in its present position after the file is closed, specify the NO REWIND phrase on the CLOSE statement. When NO REWIND is specified, the reel is not rewound.
For sequential multivolume tape files, the REEL/UNIT FOR REMOVAL phrase causes the current volume to be rewound and unloaded. The system is then notified that the volume has been removed.
For further details on rewinding and unloading volumes, refer to the discussion on the Format 1 CLOSE statement in the WebSphere Development Studio: ILE COBOL Reference.
When reading or writing variable length records to a tape file, ensure that the maximum variable length record is less than or equal to the maximum record length for the tape. The maximum record length for the tape is determined at the time that it is opened for OUTPUT. If the maximum record length on the tape is less than any of the variable length records being written to it, then these records will be truncated to the maximum record length for the tape.
You use the Format 1 READ statement to read a record from a sequential file stored on a tape device. The READ statement makes the next logical record from the file available to your ILE COBOL program.
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 file description entries for the file.
You use the Format 1 WRITE statement to write a variable length record to a sequential file stored on a tape device. 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.