DELETE Statement

The DELETE statement logically removes a record from a file or a file from the host system.

Format 1

DELETE file-name RECORD

   [ INVALID KEY statement-1 ]

   [ NOT INVALID KEY statement-2 ]

   [ END-DELETE ]

Format 2

DELETE FILE file-name

Syntax Rules

  1. file-name must refer to a file described in the Data Division. It may not be a sort file. In Format 1, it cannot be the name of a sequential file.
  2. statement-1 and statement-2 are imperative statements.
  3. The INVALID KEY and NOT INVALID KEY clauses must not be specified for a DELETE statement that references a file that is in the sequential access mode.
  1. The file must reside on a mass-storage device and be open in the I/O mode when the DELETE statement executes.
  2. For files in the sequential access mode, the last I/O statement executed for the file prior to the execution of the DELETE statement must have been a successful READ statement. The DELETE statement deletes that record from the file.
  3. For a relative file in the random or dynamic access mode, the DELETE statement removes the record identified by the file's RELATIVE KEY data item. If that record does not exist, an invalid key condition exists.
  4. For an indexed file in the random or dynamic access mode, the DELETE statement removes the record identified by that file's RECORD KEY data item. If that record does not exist, an invalid key condition exists.
  5. After a successful DELETE, the deleted record has been logically removed from the file and may no longer be accessed.
  6. The execution of the DELETE statement does not affect the file's record area.
  7. The current file position is not changed by the DELETE statement.
  8. The FILE STATUS variable of the file is updated.
  9. If there is an applicable USE AFTER EXCEPTION procedure, it executes whenever a non-zero I/O status applies to the DELETE. However, it does not execute if an invalid key condition exists and the INVALID KEY phrase is used. If a USE AFTER EXCEPTION procedure would normally execute, but none has been specified, then the program prints an error message and halts.
  10. statement-1 is executed if it is specified and the invalid key condition exists.
  11. statement-2 is executed if it is specified and the DELETE statement is successful.

Format 2 - DELETE FILE General Rules

  1. The DELETE FILE statement removes a file from the host computer system. The file named by file-name must be closed and reside on a mass-storage device.
  2. With one exception, the organization and record layout of file-name need not match the file being deleted, although it is highly recommended that they do. For Vision Version 5 and 4 files, the organization and record layout of file-name must match the file being deleted.
  3. If you match the type of the file referenced (sequential, relative, or indexed) with the type of the file being removed, your programs will consistently work with versions of ACUCOBOL-GT based on different file systems. For example, C-ISAM and Vision Versions 5 and 4 implement indexed files using two physical disk files for each COBOL indexed file. An ACUCOBOL-GT runtime using Vision Version 5, 4, or C-ISAM needs to know if an index file is being removed so that it will look for both physical files when an indexed file is removed.

    When the DELETE statement executes, file-name is translated as for the OPEN statement, and the corresponding file is removed from the system.

  4. The FILE STATUS data item is updated by the DELETE FILE statement.