Logo 
Search:

Cobol Articles

Submit Article
Home » Articles » Cobol » Homework HelpRSS Feeds

Program to describe the FILE Read Operation

Posted By: Jarvia Miller     Category: Cobol     Views: 2455

Write a program to describe the FILE Read Operation.

Code for Program to describe the FILE Read Operation in Cobol

       IDENTIFICATION DIVISION.
        PROGRAM-ID. PROG1.

       ENVIRONMENT DIVISION.
        INPUT-OUTPUT SECTION.
         FILE-CONTROL.
          SELECT INP ASSIGN TO DISK
          ORGANIZATION IS RELATIVE
          ACCESS MODE IS  SEQUENTIAL.
          

          SELECT INP1 ASSIGN TO DISK
          ORGANIZATION IS RELATIVE
          ACCESS MODE IS  RANDOM
          RELATIVE KEY IS R-NO.


       DATA DIVISION.
        FILE SECTION.
         FD INP
         LABEL RECORDS ARE STANDARD
         VALUE OF FILE-ID "INPUT1".
          01 REC1.
            02 ROLLNO1    PIC 99.
            02 NAME1      PIC X(20).
            02 ADDRESS1   PIC X(20).
         FD INP1
         LABEL RECORDS ARE STANDARD
         VALUE OF FILE-ID "INPUT1".
          01 REC2.
            02 ROLLNO2    PIC 99.
            02 NAME2      PIC X(20).
            02 ADDRESS2   PIC X(20).


       WORKING-STORAGE SECTION.
        01 EOF      PIC X VALUE "Y".
        01 CHOICE   PIC X.
        01 ANS      PIC X VALUE "Y".
        01 R-NO     PIC 99.

       PROCEDURE DIVISION.
        START1.
      *   OPEN I-O INP.

         PERFORM UNTIL ANS="N"

         DISPLAY " ENTER YOUR CHOICE "
         DISPLAY "1) ENTER NEW STUDENT RECORD"
         DISPLAY "2) SHOW ALL STUDENT RECORDS"
         DISPLAY "3) UPDATE STUDENT RECORD"
         DISPLAY "4) DELETE STUDENT RECORD"
         ACCEPT CHOICE 
               EVALUATE CHOICE 
                    WHEN 1 PERFORM INSERTION
                    WHEN 2 PERFORM READ-PARA
                    WHEN 3 PERFORM UPDATE-PARA
                    WHEN 4 PERFORM DELETE-PARA
               END-EVALUATE
               DISPLAY "DO YOU WANT TO CONTINUE (Y/N):"
               ACCEPT  ANS
         END-PERFORM.
         CLOSE INP.
         STOP RUN.

         INSERTION.
           OPEN OUTPUT INP .
           MOVE "Y" TO EOF.
           PERFORM UNTIL EOF="N"
            DISPLAY "ENTER ROLL NO :" WITH NO ADVANCING
            ACCEPT ROLLNO1
            DISPLAY "ENTER NAME :" WITH NO ADVANCING
            ACCEPT NAME1
            DISPLAY "ENTER ADDRESS :" WITH NO ADVANCING
            ACCEPT ADDRESS1
            WRITE REC1
            DISPLAY "ENTER MORE RECORD (Y/N):" WITH NO ADVANCING
            ACCEPT EOF
            
           END-PERFORM.
           CLOSE INP.

         READ-PARA.
           OPEN INPUT INP.
           MOVE "Y" TO EOF.
           PERFORM UNTIL EOF="N"
            READ REC1
               AT END MOVE "Y" TO EOF
               NOT AT AND PERFORM READ-PARA1
            END-READ
           END-PERFORM.
           CLOSE INP.
         READ-PARA1.  

          DISPLAY "ROLL NO IS :"ROLLNO1.
          DISPLAY "NAME IS :"NAME1.
          DISPLAY "ADDRESS IS :"ADDRESS1.
         

         UPDATE-PARA.
          OPEN I-O INP1.
          DISPLAY "ENTER THE ROLL-NO : " WITH NO ADVANCING
          ACCEPT R-NO.

         READ INP
           INVALID KEY 
               DISPLAY "INVALID KEY !"
           NOT INVALID KEY PERFORM UPDATE-PARA1
         END-READ.
         CLOSE INP1.
        
           UPDATE-PARA1.
           DISPLAY "NAME : " WITH NO ADVANCING
           ACCEPT NAME2
           DISPLAY "ADDRESS : " WITH NO ADVANCING
           ACCEPT ADDRESS2.
           REWRITE REC2.

        DELETE-PARA.
          OPEN INPUT INP1.
          DISPLAY "ENTER ROLL-NO U WANT TO DELETE : " WITH NO ADVANCING
          ACCEPT R-NO.
          READ INP
           INVALID KEY 
               DISPLAY "INVALID KEY !"
           NOT INVALID KEY 
           DELETE INP REC2
           END-READ.
           CLOSE INP1.

**********
INPUT FILE 
**********

121234567890123456789012345678901234567890

08SANJAY DALWADI      HANSOL AHMEDABAD
29RAJIV MODH          NARNGPURA AHMEDABAD
55HEMAL SHETH         ANKUR AHMEDABAD

******
OUTPUT
****** 

1 ENTER NEW STUDENT RECORD
2 SHOW ALL STUDENT RECORDS
3 UPDATE STUDENT RECORD
4 DELETE STUDENT RECORD

ENTER YOUR CHOICE
1
ENTER ROLL NO : 38
ENTER NAME:PREMKIRAN PATEL
ENTER ADDRESS : PALDI AHMEDABAD
ENTER MORE RECORDS (Y/N) : N

1 ENTER NEW STUDENT RECORD
2 SHOW ALL STUDENT RECORDS
3 UPDATE STUDENT RECORD
4 DELETE STUDENT RECORD

ENTER YOUR CHOICE : 2

 38 PREMKIRAN PATEL  PALDI AHMEDABAD   
 08 SANJAY DALWADI   HANSOL AHMEDABAD   
 29 RAJIV MODH       NAVRANGPURA AHMEDABAD   
 55 HEMAL SEHT       ANKUR AHMEDABAD   
  
Share: 


Didn't find what you were looking for? Find more on Program to describe the FILE Read Operation Or get search suggestion and latest updates.

Jarvia Miller
Jarvia Miller author of Program to describe the FILE Read Operation is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!