CLOSE Statement COBOL

The CLOSE statement terminates the processing of reels or units, and files with optional rewind, lock, or both, or removal where applicable.

CLOSE Statement

The files referenced in the CLOSE statement need not all have the same organization or access.

The NO REWIND, REEL, and UNIT phrases may only be specified for files that are sequential organization.

The function of a CLOSE statement (with no options) is to cause the runtime system to close the file. For files opened for OUTPUT, the runtime system also writes an EOF as it closes the file.

If a STOP RUN statement is executed prior to closing the file, the runtime system closes the file.Such a close is equivalent to the execution of a CLOSE statement except that any associated USE procedure is not executed.

A CLOSE statement may be executed only for a file in an open mode.

Once a CLOSE statement without the REEL or UNIT phrase has been executed for a file, no other statement (except the SORT or MERGE statement with the USING or GIVING phrase) can be executed that references that file, either explicitly or implicitly, unless an intervening OPEN statement for that file is executed.

The execution of a CLOSE statement causes the value of the file status data item, if any, associated with file-name-1 to be updated.

REEL and UNIT Phrase

REEL and UNIT Phrase

The REEL and UNIT phrases are synonymous in this context.The CLOSE REEL and CLOSE UNIT statements cause processing to be discontinued on the current volume and to be continued on the next volume of a multivolume series.CLOSE REEL and CLOSE UNIT on a single-volume file are ignored.

The REEL and UNIT phrases may only be specified for sequential organization files. The action of the phrase for multivolume disk files and tape files depends on the open mode:

  • For files that are open OUTPUT, the current volume is closed.The next WRITE statement will cause the record to be written to the next volume in the series.If no next volume is described or available to the series, an error occurs.
  • For files that are open INPUT or I-O, the current volume is closed.The next READ statement will obtain the first record from the next volume in the series.If no next volume exists for the file, the next READ statement causes an at end condition.

NO REWIND Phrase

WITH NOREWIND

The NO REWIND phrase may be used to write and read multiple files on a tape with a single file-name.The phrase suppresses the automatic rewinding of a tape volume when a CLOSE statement, without the NO REWIND phrase, is executed.

The NO REWIND phrase may only be specified for sequential organization files.

Following a CLOSE file-name-1 WITH NO REWIND, an OPEN file-name-1 WITH NO REWIND may be used to write or read the next file on the tape.For input, the file must be closed without rewinding after reading all the records in the file; otherwise, the open without rewinding will fail since the tape is not positioned at the beginning of a file.

The NO REWIND phrase is ignored for files that are not on tape or directed to a printer.

Specifying both the UNIT or REEL phrase and the NO REWIND phrase for a single file-name within a CLOSE statement is an allowed syntactical form, but in such a case the NO REWIND phrase has no meaning and is ignored at execution time.

REMOVAL Phrase

FOR REMOVAL

The REMOVAL phrase may be used so that the operating system is notified that the reel or unit is logically removed from this run unit.However, the reel or unit may be accessed again, in its proper order of reels and units within the file, if a CLOSE statement without the REEL or UNIT phrase is subsequently executed for this file followed by the execution of an OPEN statement for the file.

The REMOVAL phrase may only be specified for sequential organization files.

The NO REWIND and REMOVAL phrases have no effect at object time if they do not apply to the storage medium on which the file resides.

LOCK Phrase

WITH LOCK

The function of the CLOSE WITH LOCK statement is to perform the CLOSE function and set a flag to prevent the file from being opened again during execution of this program.In some runtime environments, the CLOSE WITH LOCK statement frees system resources that would otherwise not be freed until the run unit terminates.

The execution of a CLOSE statement always releases any file lock or record locks held by the run unit for file-name-1. The LOCK phrase of the CLOSE statement is unrelated to file locking and record locking.

CLOSE Statement Examples



Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

COBOL Topics