An employee record contains Badge Number/Employee Number, Name of Employee, Basic Pay, DA, HRA and Deductions. Write a COBOL program to accept details of a set of employees through keyboard and stored in a sequential file and print the contents of the file in a neat format.


      *
      *   An employee record contains Badge Number/Employee Number,
      *   Name of Employee, Basic Pay, DA, HRA and Deductions.
      *
      *   Write a COBOL program to accept details of a set of
      *   employees through keyboard and stored in a sequential file
      *   and print the contents of the file in a neat format.
      *
       IDENTIFICATION DIVISION.
       PROGRAM-ID. CREATING-EMPLOYEE-SEQ-FILE.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT EMP-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  EMP-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "EMP.DAT"
           DATA RECORD IS EMP-REC.
       01  EMP-REC.
           02 BADNO      PIC 9(3).
           02 NAME       PIC X(20).
           02 BASIC-PAY  PIC 9(5)V99.
           02 DA         PIC 9(5)V99.
           02 HRA        PIC 9(5)V99.
           02 DEDUCTION  PIC 9(5)V99.
       WORKING-STORAGE SECTION.
       01  E-EMP-REC.
           02 FILLER     PIC XX.
           02 BADNO      PIC ZZ9.
           02 FILLER     PIC XXX.
           02 NAME       PIC X(20).
           02 FILLER     PIC XX.
           02 BASIC-PAY  PIC Z(4)9.99.
           02 FILLER     PIC XXX.
           02 DA         PIC Z(4)9.99.
           02 FILLER     PIC XXX.
           02 HRA        PIC Z(4)9.99.
           02 FILLER     PIC XXX.
           02 DEDUCTION  PIC Z(4)9.99.
       01  OPTION       PIC X VALUE IS "Y".
       PROCEDURE DIVISION.
       MAIN-PARA.
           PERFORM OPEN-PARA.
           PERFORM WRITE-PARA UNTIL OPTION NOT = "Y".
           PERFORM SECOND-OPEN-PARA.
           PERFORM READ-PARA.
       OPEN-PARA.
           OPEN OUTPUT EMP-FILE.
       WRITE-PARA.
           DISPLAY (01 01) ERASE.
           DISPLAY (02 10) "Enter the following details of an Employee".
           DISPLAY (03 10) "------------------------------------------".
           DISPLAY (04 10) "  Badge/Emp. No.: ".
           ACCEPT (04 28) BADNO OF EMP-REC.
           DISPLAY (05 10) "Name of Employee: ".
           ACCEPT (05 28) NAME OF EMP-REC.
           DISPLAY (06 10) "      Basic Pay : ".
           ACCEPT (06 28) BASIC-PAY OF EMP-REC.
           DISPLAY (07 10) "             DA : ".
           ACCEPT (07 28) DA OF EMP-REC.
           DISPLAY (08 10) "            HRA : ".
           ACCEPT (08 28) HRA OF EMP-REC.
           DISPLAY (09 10) "      Deduction : ".
           ACCEPT (09 28) DEDUCTION OF EMP-REC.
           WRITE EMP-REC.
           DISPLAY (12 10) "Press Y/y to add more Employee : ".
           ACCEPT (12 44) OPTION.
           IF OPTION = "y"
              MOVE "Y" TO OPTION.
       SECOND-OPEN-PARA.
           CLOSE EMP-FILE.
           OPEN INPUT EMP-FILE.
           DISPLAY (01 01) ERASE.
           DISPLAY "----------------------------------------------------
      -    "-------------------".
           DISPLAY "Emp.No. Name of Employee     Basic Pay       D.A.
      -    "  H.R.A.  Deduction".
           DISPLAY "----------------------------------------------------
      -    "-------------------".
       READ-PARA.
           READ EMP-FILE RECORD AT END GO TO CLOSE-PARA.
           MOVE CORRESPONDING EMP-REC TO E-EMP-REC.
           DISPLAY E-EMP-REC.
           GO TO READ-PARA.
       CLOSE-PARA.
           DISPLAY "====================================================
      -    "===================".
           CLOSE EMP-FILE.
           STOP RUN.

No comments:

Post a comment