COBOL Program to
implement Relative File concept.
PROGRAM:
IDENTIFICATION DIVISION.
PROGRAM-ID. RELFILE.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT RELA-FILE ASSIGN TO DISK
ORGANIZATION IS RELATIVE ACCESS MODE
IS SEQUENTIAL
RELATIVE KEY IS SLNO.
DATA DIVISION.
FILE SECTION.
FD RELA-FILE
LABEL RECORDS ARE STANDARD VALUE OF
FILE-ID IS "STUREL.DAT".
01 RELA-REC.
02 SLNO PIC 9(2).
02 REGNO PIC X(5).
02 SNAME PIC X(20).
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
RELATIVE FILE".
DISPLAY
"-------------------------------------".
OPEN OUTPUT RELA-FILE.
MOVE 1 TO SLNO.
MOVE 'Y' TO CH1.
PERFORM READ-PARA UNTIL CH1 = 'N'.
CLOSE RELA-FILE.
COMPUTE CH2 = 1.
PERFORM MENU-PARA UNTIL CH2 = 3.
STOP RUN.
MENU-PARA.
DISPLAY "1. TO VIEW THE
CONTENTS OF THE FILE".
DISPLAY "2. TO RECREATE
FILE".
DISPLAY "3. EXIT".
ACCEPT CH2.
IF CH2 = 1
PERFORM INI-PARA.
IF CH2 = 2
OPEN OUTPUT RELA-FILE
MOVE 'Y' TO CH1
PERFORM READ-PARA UNTIL CH1 = 'N'
CLOSE RELA-FILE.
READ-PARA.
COMPUTE SLNO = SLNO + 1.
DISPLAY "ENTER THE REG NO
:".
ACCEPT REGNO.
DISPLAY "ENTER THE NAME OF THE
STUDENT :".
ACCEPT SNAME.
WRITE RELA-REC.
DISPLAY "DO YOU WISH TO
CONTINUE ? ".
ACCEPT CH1.
VIEW-PARA.
DISPLAY REGNO, SNAME.
READ RELA-FILE NEXT RECORD AT END
MOVE 'Y' TO EOF.
INI-PARA.
OPEN INPUT RELA-FILE.
MOVE 'N' TO EOF.
DISPLAY "REGNO NAME ".
READ RELA-FILE RECORD AT END
MOVE
'Y' TO EOF.
PERFORM VIEW-PARA UNTIL EOF = 'Y'.
CLOSE RELA-FILE.
No comments:
Post a Comment