HP 3000 Manuals

DELETE Statement [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation


HP COBOL II/XL Reference Manual

DELETE Statement 

The DELETE statement logically removes a record from a relative or
indexed file.

Syntax 

[]
Parameters file-name-1 the name of the file from which the record is to be deleted. The file must be an indexed or relative file opened in input-output mode. imperative-statement-1 one or more imperative statements. and imperative-statement-2 Description If the specified file is being used in sequential access mode, the INVALID KEY or NOT INVALID KEY phrase must not be specified. However, if the file is being used in any other access mode and there is no applicable USE procedure, these clauses must be specified.[REV BEG] For information on handling I/O errors, see "Input-Output Error Handling Procedures" .[REV END] After a successful execution of a DELETE statement, the selected record has been logically removed from the file, and can no longer be accessed.
NOTE "Logically removed" means that the record has been marked for deletion, and not physically removed. The contents of the record area associated with the specified file are unaffected. The file position indicator is also unaffected.
The execution of the DELETE statement causes the value of the FILE STATUS data item, if specified for the file, to be updated. Refer to "FILE STATUS Clause" in Chapter 6 for valid status keys. Selection of the record to be deleted is accomplished in one of two ways, depending upon what access mode is specified for the file. For files being used in sequential access mode, the record to be deleted is the last record read by a successfully executed READ statement. The READ statement must be the last input-output operation performed on the file prior to execution of the DELETE statement. For files in dynamic or random access mode, the record removed is that record identified by the contents of the RELATIVE KEY or RECORD KEY data item associated with the specified file. If the file does not contain the record specified by the key, an INVALID KEY condition exists. If the INVALID KEY phrase has been specified, and the execution of a DELETE statement causes an INVALID KEY condition, the imperative statements specified in the INVALID KEY phrase are executed. Any USE procedure specified for the file is ignored. When no INVALID KEY condition exists, control is transferred to the end of the DELETE statement or to the imperative statement specified in the NOT INVALID KEY phrase, if specified.[REV BEG] For more information on handling I/O errors, see "Input-Output Error Handling Procedures" .[REV END] For indexed files, if the primary record key has duplicates specified for it, you should use the DELETE statement only when the file is open in sequential access mode. This is because a DELETE statement for such files open in dynamic or random access mode deletes the first record written to the file that has the same primary key value as the value placed in the RECORD KEY data item. This first occurrence of the duplicate value may not be the record you want to delete. Example The following example shows the DELETE statement: : ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT REL-FILE ASSIGN TO "DATAFL1" ORGANIZATION IS RELATIVE ACCESS MODE IS SEQUENTIAL FILE STATUS IS CHK-REL-FILE. SELECT INDX-FILE ASSIGN TO "DATAFL2" ORGANIZATION IS INDEXED ACCESS MODE IS RANDOM RECORD KEY IS KEY-DATA FILE STATUS IS CHK-INDX-FILE. DATA DIVISION. FILE SECTION. FD REL-FILE. 01 REL-DATA 02 DATA-1 PIC 99. FD INDX-FILE. 01 INDX-DATA. 02 KEY-DATA PIC X(5). PROCEDURE DIVISION. : OPEN I-O REL-FILE INDX-FILE. READ REL-FILE RECORD AT END STOP RUN. IF DATA-1 IS EQUAL TO 0 THEN DELETE REL-FILE RECORD. : MOVE "MEYER" TO KEY-DATA. DELETE INDX-FILE RECORD INVALID KEY PERFORM CHECK-OUT. : CHECK-OUT. DISPLAY "VALUE OF CHK-INDX-FILE IS" CHK-INDX-FILE. DISPLAY "WHAT ACTION TO BE TAKEN?". ACCEPT ACTION-ITEM.


MPE/iX 5.0 Documentation