UNLOCK Statement
The UNLOCK
statement removes record locks.
General Format:
UNLOCK file-1 {RECORD }
{RECORDS}
Syntax:
file-n
is a file described in the File Section with an FD.
General Rules:
file-1
must beOPEN
when theUNLOCK
statement is executed.- The
UNLOCK
statement releases record locks forfile-1
.
Code Sample:
IDENTIFICATION DIVISION.
PROGRAM-ID. UNLOCK-1.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT RESWORDS ASSIGN TO "RESWORDS"
ORGANIZATION IS INDEXED
ACCESS IS DYNAMIC
RECORD KEY IS RESERVED-WORD
FILE STATUS IS RESWORDS-STAT.
DATA DIVISION.
FILE SECTION.
FD RESWORDS.
01 RESWORDS-RECORD.
03 RESERVED-WORD PIC X(30).
03 COMMENT PIC X(20).
WORKING-STORAGE SECTION.
77 RESWORDS-STAT PIC XX.
88 END-OF-RESWORDS VALUE "10".
77 DUMMY PIC X.
PROCEDURE DIVISION.
MAIN.
OPEN OUTPUT RESWORDS.
MOVE "ACCEPT" TO RESERVED-WORD.
MOVE "HELLO WORLD" TO COMMENT.
WRITE RESWORDS-RECORD.
CLOSE RESWORDS.
OPEN I-O RESWORDS.
MOVE "ACCEPT" TO RESERVED-WORD.
READ RESWORDS WITH LOCK.
UNLOCK RESWORDS RECORD.
DISPLAY "UNLOCK [FILE] RECORD" LINE 5 COL 10.
MOVE "ACCEPT" TO RESERVED-WORD.
READ RESWORDS WITH LOCK.
UNLOCK RESWORDS RECORDS.
DISPLAY "UNLOCK [FILE] RECORDS" LINE 7 COL 10.
DISPLAY "UNLOCK-1 FINISHED!" LINE 11 COL 10.
ACCEPT DUMMY LINE 11 COL 35.
CLOSE RESWORDS.
STOP RUN.