The following example shows how to update an existing record in the file.
Input:1111 ABDUL 01 |
IDENTIFICATION DIVISION. PROGRAM-ID. COBRWRTE. 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 CLASS 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. READ STUDENT KEY IS STUDENT-ID INVALID KEY DISPLAY ‘KEY IS NOT EXISTING’ END-READ. MOVE 'ABDUL KALAM' TO NAME. REWRITE STUDENT-FILE END-REWRITE. CLOSE STUDENT. STOP RUN. |
1111 ABDUL KALAM 01 |
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!