UNLOCK Statement

The UNLOCK statement removes file record locks.

Format 1

UNLOCK file-name ALL {RECORD }

Format 2


Format 3


Syntax Rule

file-name is a relative or indexed file described in the Data Division.

Format 1 General Rules

  1. file-name must be in the open mode when the UNLOCK statement executes.
  2. When the UNLOCK statement executes, the currently locked records (if any) for file-name are unlocked and made available to other users. The statement has no effect if there are no records locked for file-name.
  3. The UNLOCK statement will fail only when the file is not open. The UNLOCK statement updates the file's associated FILE STATUS data item.
  4. During a transaction, the UNLOCK statement affects only those files for which rollback has not been enabled. In the case where the UNLOCK statement is ineffective because rollback has been enabled for the file, the file status will be set to 00 (success).

Format 2

  1. A Format 2 UNLOCK statement releases all records locked by all of the open files in the program.
  2. A Format 2 UNLOCK always succeeds. No file status data items are updated by this verb and no Declarative procedures are ever executed.

Format 3 General Rules

A Format 3 UNLOCK THREAD statement removes the last lock applied to the thread. If the thread has only one lock (only one LOCK THREAD statement has executed in the thread), then the UNLOCK THREAD statement has the effect of allowing other threads to run. If more than one lock has been applied to the thread, then the UNLOCK THREAD statement removes the last lock applied to the thread and the thread remains locked until it has been unlocked as many time as it was locked. This allows a thread to lock itself, call a subroutine that also locks itself, and remain locked when that subroutine unlocks itself. See the entry in this section for LOCK THREAD.

If the current thread is not locked, the UNLOCK THREAD statement has no effect.