The DELETE statement logically removes a record from a mass storage file. It can be specified only for files with relative
or indexed organization.
General Format
General Rules
- The associated file must be open in the I-O mode at the time of execution of this statement. (See the topic
The OPEN Statement.)
- For files in sequential access mode, the last input-output statement executed for file-name-1 prior to the execution of the
DELETE statement must have been a successfully executed READ statement. The operating system logically removes from the file
the record that was accessed by that READ statement.
- For a file in random or dynamic access mode, the operating system logically removes from the file that record identified
by the contents of a key data item associated with file-name. For a relative file, this key data item is the relative key
and for an indexed file, it is the prime record key. If the file does not contain the record specified by the key, an INVALID
KEY condition exists. (See the section
The INVALID KEY Condition in the chapter
Procedure Division.)
- After the successful execution of a DELETE statement, the identified record is logically removed from the file and can no
longer be accessed.
- The execution of a DELETE statement does not affect the contents of the record area associated with file-name-1.
- The file position indicator is not affected by the execution of a DELETE statement.
- Execution of the DELETE statement causes the value of the specified FILE STATUS data item, if any, associated with the file-name
to be updated. (See the topic
I-O Status in the chapter
Procedure Division.)
- Transfer of control following the successful or unsuccessful execution of the DELETE operation depends on the presence or
absence of the optional INVALID KEY phrase
and NOT INVALID KEY phrase
in the DELETE statement. (See the topic
The INVALID KEY Condition in the chapter
Procedure Division.)
- The END-DELETE phrase delimits the scope of the DELETE statement. (See the section
Explicit and Implicit Scope Terminators in the chapter
Concepts of the COBOL Language.)
- When using DELETE, the record to be deleted must not be locked by another run unit.
- Following the successful execution of a DELETE statement, any record lock held by the run unit on the deleted record is released.