Processing Files and Records
6.5 Updating Files
Example 640 (Cont.) Deleting Relative Records in Sequential Access Mode
ACCESS MODE IS SEQUENTIAL
RELATIVE KEY IS KETCHUP-MASTER-KEY.
DATA DIVISION.
FILE SECTION.
FD FLAVORS.
01 KETCHUP-MASTER PIC X(50).
WORKING-STORAGE SECTION.
01 KETCHUP-MASTER-KEY PIC 99 VALUE 1.
PROCEDURE DIVISION.
A000-BEGIN.
OPEN I-O FLAVORS.
PERFORM A010-DELETE-RECORDS UNTIL KETCHUP-MASTER-KEY = 00.
A005-EOJ.
DISPLAY "END OF JOB".
CLOSE FLAVORS.
STOP RUN.
A010-DELETE-RECORDS.
DISPLAY "TO DELETE A RECORD ENTER ITS RECORD NUMBER".
ACCEPT KETCHUP-MASTER-KEY.
IF KETCHUP-MASTER-KEY NOT = 00 PERFORM A200-READ-FLAVORS
DELETE FLAVORS RECORD.
A200-READ-FLAVORS.
START FLAVORS
INVALID KEY DISPLAY "INVALID START"
STOP RUN.
READ FLAVORS AT END DISPLAY "FILE AT END"
GO TO A005-EOJ.
Deleting Relative Records in Random Access Mode
Deleting a relative record in random access mode involves the following:
1. Specifing ORGANIZATION IS RELATIVE in the Environment Division
SELECT clause
2. Specifying ACCESS MODE IS RANDOM in the Environment Division
SELECT clause
3. Opening the file for I-O
4. Moving the relative record number value to the RELATIVE KEY data name
5. Deleting the record identified by the relative record number
If the file does not contain a valid record, an invalid key condition exists.
Example 6–41 deletes relative records in random access mode.
Example 641 DeletingRelative Records in Random Access Mode
IDENTIFICATION DIVISION.
PROGRAM-ID. REL10.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT FLAVORS ASSIGN TO "BRAND"
ORGANIZATION IS RELATIVE