Logo 
Search:

Cobol Articles

Submit Article
Home » Articles » Cobol » Homework HelpRSS Feeds

PROGRAM FOR ADD,UPDATE & DELETE OPERATION BY USING INDEX SEQUENTIAL FILE

Posted By: Holly Brown     Category: Cobol     Views: 8033

PROGRAM FOR ADD,UPDATE & DELETE OPERATION BY USING INDEX SEQUENTIAL FILE.

Code for PROGRAM FOR ADD,UPDATE & DELETE OPERATION BY USING INDEX SEQUENTIAL FILE in Cobol

       IDENTIFICATION DIVISION.
        PROGRAM-ID. IDX1.
       ENVIRONMENT DIVISION.
        FILE-CONTROL.
          SELECT TRAN-FILE1 ASSIGN TO DISK
          ORGANIZATION IS LINE SEQUENTIAL.

          SELECT IDX-FILE ASSIGN TO "INDEX.TXT"
           ORGANIZATION IS INDEXED
           ACCESS IS SEQUENTIAL
           RECORD KEY IS INO1.

       DATA DIVISION.
       FILE SECTION.
         FD TRAN-FILE1
            LABEL RECORDS ARE STANDARD
            VALUE OF FILE-ID IS "MEMBER.TXT".
         01 TRAN-REC.
          05 TNO1  PIC 999.
          05 TNAME PIC X(12).

         FD IDX-FILE
             LABEL RECORDS ARE STANDARD.
         01 IDX-REC.
          05 INO1  PIC 999.
          05 INAME PIC X(12).
           
        WORKING-STORAGE SECTION.
         01 EOF PIC X VALUE 'N'.
         01 VAL PIC X(12).
         01 CH1 PIC 9.
          88 A VALUE 1.
          88 B VALUE 2.
          88 C VALUE 3.

        PROCEDURE DIVISION.
         BEGIN.
           OPEN INPUT TRAN-FILE1.

           DISPLAY "1.ADD."
           DISPLAY "2.UPDATE."
           DISPLAY "3.DELETE."
           DISPLAY "ENTER YOUR CHOICE:"
           ACCEPT CH1.

           IF A
           OPEN OUTPUT IDX-FILE
           PERFORM UNTIL EOF='Y'
            READ TRAN-FILE1
             AT END MOVE 'Y' TO EOF
             NOT AT END
                PERFORM PARA1
            END-READ
           END-PERFORM
           CLOSE IDX-FILE

           ELSE IF B
           OPEN I-O IDX-FILE

           DISPLAY "ENTER VALUE:"
           ACCEPT INO1
           DISPLAY "ENTER NAME"
           ACCEPT VAL
            READ IDX-FILE
             AT END DISPLAY "ERROR TO READ"
            END-READ
     *      MOVE INO1 TO RNO1
            MOVE VAL TO INAME
            REWRITE IDX-REC
           CLOSE IDX-FILE

           ELSE IF C
            OPEN I-O IDX-FILE
             DISPLAY "ENTER RECORD FOR DELETE"
             ACCEPT INO1

             READ IDX-FILE
              AT END DISPLAY "ERROR TO READ"
             END-READ

             DELETE IDX-FILE RECORD

           CLOSE IDX-FILE
            
           END-IF.
           CLOSE TRAN-FILE1.

           STOP RUN.

         PARA1.

           WRITE IDX-REC FROM TRAN-REC
            INVALID KEY DISPLAY "ERROR"
           END-WRITE.

**************************************************************************************************
        
    OUTPUT :

    1.ADD
    2.UPDATE
    3.DELETE
    ENTER YOUR CHOICE
    1 (COPY THE CONTENTS OF TRANSACTION FILE TO INDEX FILE)
    
    MEMBER.TXT (INDEX FILE)
    01APURVA
    02HEMAL
    
    1.ADD
    2.UPDATE
    3.DELETE
    ENTER YOUR CHOICE
    2

    ENTER VALUE : 
    2
    ENTER NAME :
    APURVA

    MEMBER.TXT (INDEX FILE)
    01APURVA
    02APURVA


    1.ADD
    2.UPDATE
    3.DELETE
    ENTER YOUR CHOICE
    3

    ENTER RECORD FOR DELETE
    2
    
    MEMBER.TXT (INDEX FILE)
    01APURVA

    
  
Share: 



Holly Brown
Holly Brown author of PROGRAM FOR ADD,UPDATE & DELETE OPERATION BY USING INDEX SEQUENTIAL FILE is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
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!