Logo 
Search:

Cobol Articles

Submit Article
Home » Articles » Cobol » Homework HelpRSS Feeds

Program to insert, update, delete and display in an index file

Posted By: Lacey Hughes     Category: Cobol     Views: 6215

Write a Program to insert, update, delete and display in an index file.

Code for Program to insert, update, delete and display in an index file in Cobol

       identification division.
       program-id. indexfile.

       environment division.
       input-output section.
       file-control.
          select fin assign to disk
          organization is indexed
          access is random
          record key is rno.

       data division.
       file section.
          fd fin 
               value of file-id is"m.txt".
               01 rec-io.
                    05 rno pic 99.
                    05 sname pic x(10).
                    05 marks pic 999.

       working-storage section.
          01 eof pic x value"Y".
            88 more-records value"Y".
            88 no-more-records value"N".
         01 eof1 pic x value"N".

          01 option pic 9.
               88 new-record value 1.
               88 update-record value 2.
               88 delete-record value 3.
               88 display-record value 4.
               88 exit1 value 0.

          01 change-name pic x.
          01 change-marks pic x.

       procedure division.
       main-para.
           open i-o fin. 

           perform option-para
               until no-more-records.
           close fin.
       para2.
       stop run.

       exit12.
          perform para2.
       option-para.

          display "select " 
          display "1. Insert New Records. ".
          display "2. Update Records. ".
          display "3. Delete Records. ".
          display "4. Display Records".
          display "0. exit".
          accept option.


          evaluate true
               
               when new-record perform insert-para
               when update-record perform update-para
               when delete-record perform delete-para
               when display-record perform display-para
               when exit1 perform para2
               when other display " Error. . . "
          
          end-evaluate.

          
          display " Do You Want To Continue(Y/N) : ".
          accept eof.

          display-para.
               close fin.
               open input fin.
      *         perform until eof1 = "Y"
      *         read fin at end move "Y" to eof1
      *              not at end
      *                   display rec-io
      *         end-read
      *         end-perform.
          display "Enter the roll no : ".
          accept rno.
          read fin.
          display rec-io.
               close fin.

          insert-para.
               display "Enter RollNo: " with no advancing.
               accept rno.
               display "Enter Name: " with no advancing.
               accept sname.
               display "Enter Marks: " with no advancing.
               accept marks.

               write rec-io 
                invalid key display "Insertion is not Possible"
               end-write.

          update-para.
               read fin
                    invalid key display "No Such Record  Found"
                    not invalid key perform update-subpara
               end-read.

          update-subpara.
               display  "U Want To change Name (Y/N): " .
               accept change-name.

               if change-name = "Y"
                    display "Enter New Name: " with no advancing
                    accept sname
               end-if.

               display "Continue Change Marks (Y/N): "
               accept change-marks.
               if change-marks= "Y"
                    display "New Marks: " with no advancing
                    accept marks
               end-if.

               rewrite rec-io
                    invalid key display "Updation Not Possible"
               end-rewrite.

          delete-para.
               delete fin record
                    invalid key display "Deletion is not Possible"
               end-delete.
  
Share: 



Lacey Hughes
Lacey Hughes author of Program to insert, update, delete and display in an index 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!