The following example shows how to delete an existing record in the file.
Input:
1111 ABDUL 01 |
IDENTIFICATION DIVISION. PROGRAM-ID. COBLDELT. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT STUDENT ASSIGN TO STD-FILE ORGANIZATION IS INDEXED ACCESS IS RANDOM RECORD KEY IS STUDENT-ID FILE STATUS IS FS. DATA DIVISION. FILE SECTION. FD STUDENT 01 STUDENT-FILE. 05 STUDENT-ID PIC 9(4). 05 NAME PIC A(12). 05 RANK PIC X(3). WORKING-STORAGE SECTION. 01 FILE STATUS PIC X(02) VALUE SPACES. PROCEDURE DIVISION. OPEN I-O STUDENT. MOVE '1111' TO STUDENT-ID. DELETE STUDENT RECORD INVALID KEY DISPLAY 'Invalid Key' NOT INVALID KEY DISPLAY 'Record Deleted' END-DELETE. CLOSE STUDENT. STOP RUN. |
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!