CLOSE Statement
The CLOSE
statement is used to CLOSE
a file or files.
General Format:
CLOSE { file-1 {REEL} [ FOR REMOVAL ] } ...
{UNIT}
[ WITH LOCK ]
[ WITH NO REWIND ]
Syntax:
file-n
is a file described in the File Section with an FD.
General Rules:
- The
CLOSE
statement may only be applied to files that are in anOPEN
state. - When a file is
CLOSE
'd, all record and file locks held by the file are released. - The
REEL
,UNIT
,FOR REMOVAL
, andWITH NO REWIND
clauses are checked for syntax, but are otherwise treated as commentary. - The
REEL
,UNIT
,FOR REMOVAL
, andWITH NO REWIND
clauses can only be used with files described withORGANIZATION SEQUENTIAL
. CLOSE file-1 WITH LOCK
preventsfile-1
from beingOPEN
’ed again in the same program instance.- The
CLOSE
operation updates theFILE STATUS
variable.
Code Sample:
IDENTIFICATION DIVISION.
PROGRAM-ID. CLOSE-1.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT TAPEFILE ASSIGN TO "TAPE-1"
ORGANIZATION IS SEQUENTIAL
ACCESS IS SEQUENTIAL
FILE STATUS IS TAPEFILE-STAT.
DATADIVISION.
FILE SECTION.
FD TAPEFILE.
01 TAPEFILE-RECORD PIC X(80).
WORKING-STORAGESECTION.
77 TAPEFILE-STAT PIC XX.
77 DUMMY PIC X.
PROCEDURE DIVISION.
MAIN.
*CLOSE { FILE-NAME {REEL} [ FOR REMOVAL ] } ...
* [UNIT}
* [ WITH LOCK ]
* [ WITH NO REWIND ]
OPEN INPUT TAPEFILE.
CLOSE TAPEFILE .
OPEN INPUT TAPEFILE.
CLOSE TAPEFILE WITH NO REWIND.
OPEN INPUT TAPEFILE.
CLOSE TAPEFILE WITH LOCK.
OPEN INPUT TAPEFILE.
CLOSE TAPEFILE REEL.
OPEN INPUT TAPEFILE.
CLOSE TAPEFILE REEL FOR REMOVAL.
OPEN INPUT TAPEFILE.
CLOSE TAPEFILE UNIT.
OPEN INPUT TAPEFILE.
CLOSE TAPEFILE UNIT FOR REMOVAL.
DISPLAY "CLOSE-1 COMPLETE!" LINE 10 COL 10.
ACCEPT DUMMY LINE 10 COL 30.
STOP RUN.