Saturday, 1 March 2014

COBOL program to implement Index File Concept Using Subroutine.



COBOL program to implement Index File Concept Using Subroutine.

PRORGAM:     
       IDENTIFICATION DIVISION.
       PROGRAM-ID. INDEX-FILE.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT INDEX-FILE ASSIGN TO DISK
           ORGANIZATION IS INDEXED
           ACCESS MODE IS SEQUENTIAL RECORD KEY IS SLNO.
       DATA DIVISION.
       FILE SECTION.
       FD INDEX-FILE
           LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS "STUDIND.DAT".
       01 INDEX-REC.
           02 SLNO PIC 9(3).
           02 REGNO PIC X(5).
           02 SNAME PIC X(15).
           02 MARKS PIC 9(3).
       WORKING-STORAGE SECTION.
           77 WREGNO PIC X(5).
           77 CH1 PIC X.
           77 CH2 PIC 9.
           77 EOF PIC X.
       PROCEDURE DIVISION.
       MAIN-PARA.
           DISPLAY "CREATE AND PROCESS AN INDEXED FILE".
           OPEN OUTPUT INDEX-FILE.
           MOVE 0 TO SLNO.
           MOVE 'Y' TO CH1.
           PERFORM READ-PARA UNTIL CH1 = 'N'.
           CLOSE INDEX-FILE.
           COMPUTE CH2 = 1.
           PERFORM MENU-PARA UNTIL CH2 = 4.
           STOP RUN.
       MENU-PARA.
           DISPLAY "1. TO VIEW THE CONTENTS OF THE FILE".
           DISPLAY "2. TO RECREATE".
           DISPLAY "3. TO MODIFY A RECORD".
           DISPLAY "4. EXIT".
           ACCEPT CH2.                   
           IF CH2 = 1
           PERFORM INI-PARA.
           IF CH2 = 2
           OPEN OUTPUT INDEX-FILE
           MOVE 'Y' TO CH1
           PERFORM READ-PARA UNTIL CH1 = 'N'
           CLOSE INDEX-FILE.
           IF CH2 = 3
           CALL "PRGINDM".
       READ-PARA.
           COMPUTE SLNO = SLNO + 1.
           DISPLAY "ENTER THE REGISTER NUMBER : ".
           ACCEPT REGNO.
           DISPLAY "ENTER THE NAME OF THE STUDENT : ".
           ACCEPT SNAME.
           DISPLAY "ENTER THE MARKS : ".
           ACCEPT MARKS.
           WRITE INDEX-REC.
           DISPLAY "DO YOU WISH TO CONTINUE (Y/N) ".
           ACCEPT CH1.
       VIEW-PARA.
           DISPLAY SLNO, REGNO, SNAME, MARKS.
           READ INDEX-FILE NEXT RECORD AT END
           MOVE 'Y' TO EOF.
       INI-PARA.
           OPEN INPUT INDEX-FILE.
           MOVE 'N' TO EOF.
           DISPLAY "SL REG NAME    MARKS".
           READ INDEX-FILE RECORD AT END MOVE 'Y' TO EOF.
           PERFORM VIEW-PARA UNTIL EOF = 'Y'.
           CLOSE INDEX-FILE.





PRGINDM :

       IDENTIFICATION DIVISION.
       PROGRAM-ID. MODIFYIND.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT INDEX-FILE ASSIGN TO DISK
           ORGANIZATION IS INDEXED
           ACCESS MODE IS RANDOM RECORD KEY IS SLNO.
       DATA DIVISION.
       FILE SECTION.
       FD INDEX-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "STUDIND.DAT".
       01 INDEX-REC.
           02 SLNO PIC 9(3).
           02 REGNO PIC X(5).
           02 SNAME PIC X(15).
           02 MARKS PIC 9(3).
       WORKING-STORAGE SECTION.
           77 FLAG PIC 9 VALUE 0.
       PROCEDURE DIVISION.
       MAIN-PARA.
           OPEN I-O INDEX-FILE.
           PERFORM SEARCH-PARA.
           CLOSE INDEX-FILE.
           EXIT PROGRAM.
       SEARCH-PARA.
           DISPLAY ERASE.
           DISPLAY "ENTER THE SL NO ".
           ACCEPT SLNO.
           READ INDEX-FILE INVALID KEY
           MOVE 1 TO FLAG.
           IF FLAG = 0
           DISPLAY "RECORD FOUND"
           DISPLAY "SLNO : ", SLNO
           DISPLAY "REGNO : ", REGNO
           DISPLAY "STUDENT NAME : ", SNAME
           DISPLAY "OLD MARKS : ", MARKS
           DISPLAY "ENTER NEW MARKS:" ACCEPT MARKS
           REWRITE INDEX-REC.
           IF FLAG = 1
           DISPLAY "RECORD IS NOT FOUND".
         


No comments: