Pages

Zone wise Sale of Products details.


       IDENTIFICATION DIVISION.
       PROGRAM-ID. ZONE-SALES.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  SALES.
           02 PRODUCT OCCURS 4 TIMES.
              03  ZONE  PIC 9999 OCCURS 5 TIMES.
       77  I         PIC 9.
       77  J         PIC 9.
       77  BP        PIC 9999.
       77  BZ        PIC Z.
       01  DISP-HEAD PIC X(20) VALUE "  Z1  Z2  Z3  Z4 TOT".
       01  UL        PIC X(20) VALUE ALL "-".
       01  DISP-REC.
           02 E-Z1   PIC ZZZ9.
           02 E-Z2   PIC ZZZ9.
           02 E-Z3   PIC ZZZ9.
           02 E-Z4   PIC ZZZ9.
           02 E-Z5   PIC ZZZ9.

       PROCEDURE DIVISION.
       MAIN-PARA.
           PERFORM READ-DATA VARYING I FROM 1 BY 1 UNTIL I > 3
                   AFTER J FROM 1 BY 1 UNTIL J > 4.
           PERFORM SUM-PARA1 VARYING I FROM 1 BY 1 UNTIL I > 4.
           PERFORM SUM-PARA3 VARYING I FROM 1 BY 1 UNTIL I > 3.
           DISPLAY DISP-HEAD.
           DISPLAY UL.
           PERFORM DISP-PARA VARYING I FROM 1 BY 1 UNTIL I > 4.
           DISPLAY UL.
           PERFORM COM-PARA1 VARYING I FROM 1 BY 1 UNTIL I > 3.
           DISPLAY " ".
           STOP RUN.
       READ-DATA.
           DISPLAY "Enter Quantity of Product : " I " of Zone : " J.
           ACCEPT ZONE(I, J).
       SUM-PARA1.
           MOVE 0 TO ZONE(4, I).
           PERFORM SUM-PARA2 VARYING J FROM 1 BY 1 UNTIL J > 3.
       SUM-PARA2.
           COMPUTE ZONE(4, I) = ZONE(4, I) + ZONE(J, I).
       SUM-PARA3.
           MOVE 0 TO ZONE(I, 5).
           PERFORM SUM-PARA4 VARYING J FROM 1 BY 1 UNTIL J > 4.
       SUM-PARA4.
           COMPUTE ZONE(I, 5) = ZONE(I, 5) + ZONE(I, J).
       DISP-PARA.
           MOVE ZONE(I, 1) TO E-Z1.
           MOVE ZONE(I, 2) TO E-Z2.
           MOVE ZONE(I, 3) TO E-Z3.
           MOVE ZONE(I, 4) TO E-Z4.
           MOVE ZONE(I, 5) TO E-Z5.
           DISPLAY DISP-REC.
       COM-PARA1.
           MOVE 0 TO BP.
           MOVE 0 TO BZ.
           PERFORM COM-PARA2 VARYING J FROM 1 BY 1 UNTIL J > 4.
           DISPLAY "Product : " I " Sold More in Zone : " BZ.
       COM-PARA2.
           IF ZONE(I, J) > BP
              MOVE ZONE(I, J) TO BP
              MOVE J TO BZ.

Sorting Sample Program using COBOL


      *
      *   A student record have the following structure:
      *
      *   Register Number,
      *   Name of the Student,
      *   Course and
      *   Year of Admin.
      *
      *   Write a COBOL program to read details of a set of students
      *   through the keyboard and stored in a sequential file and
      *   generate a list of students joined for various courses in
      *   different year in a suitable order using SORT verb of COBOL.
      *
       IDENTIFICATION DIVISION.
       PROGRAM-ID. SORTING.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT STU-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
           SELECT WORK-FILE ASSIGN TO DISK.
           SELECT SORT-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  STU-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "STU.DAT"
           DATA RECORD IS STU-REC.
       01  STU-REC.
           02 REGNO    PIC 9(3).
           02 NAME     PIC X(30).
           02 COURSE   PIC X(10).
           02 YOA      PIC 9(4).
       SD  WORK-FILE
           DATA RECORD IS WORK-REC.
       01  WORK-REC.
           02 W-REGNO  PIC 9(3).
           02 W-NAME   PIC X(30).
           02 W-COURSE PIC X(10).
           02 W-YOA    PIC 9(4).
       FD  SORT-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "SORT.DAT"
           DATA RECORD IS SORT-REC.
       01  SORT-REC.
           02 S-REGNO  PIC 9(3).
           02 S-NAME   PIC X(30).
           02 S-COURSE PIC X(10).
           02 S-YOA    PIC 9(4).
       WORKING-STORAGE SECTION.
       01  SHOW-REC.
           02 S-REGNO  PIC 9(3).
           02 FILLER   PIC X(3).
           02 S-NAME   PIC X(30).
           02 FILLER   PIC X(3).
           02 S-COURSE PIC X(10).
           02 FILLER   PIC X(3).
           02 S-YOA    PIC 9(4).
       77  FLAG        PIC X.
       77  UL          PIC X(56) VALUE ALL "-".
       77  DL          PIC X(56) VALUE ALL "=".
       PROCEDURE DIVISION.
       MAIN-PARA.
           OPEN OUTPUT STU-FILE.
       DATA-GET.
           DISPLAY (01 01) ERASE.
           DISPLAY "-------------------------------".
           DISPLAY "        DATA INPUT FORM".
           DISPLAY "-------------------------------".
           DISPLAY "Enter Reg.No : ".
           ACCEPT REGNO.
           DISPLAY "  Enter Name : ".
           ACCEPT NAME.
           DISPLAY "Enter Course : ".
           ACCEPT COURSE.
           DISPLAY "   Enter YOA : ".
           ACCEPT YOA.
           WRITE STU-REC.
           DISPLAY "-------------------------------".
           DISPLAY "Press Y/y to Continue...".
           ACCEPT FLAG.
           IF FLAG = "Y" OR FLAG = "y" GO TO DATA-GET.
       CLOSE-PARA.
           CLOSE STU-FILE.
       SORT-PARA.
           SORT WORK-FILE ON ASCENDING KEY W-YOA, W-COURSE, W-REGNO
           USING STU-FILE
           GIVING SORT-FILE.
       OPEN-UNSORT.
           OPEN INPUT STU-FILE.
           DISPLAY (01 01) ERASE.
           DISPLAY UL.
           DISPLAY "                     UNSORTED DATA".
           DISPLAY DL.
       READ-UNSORT.
           READ STU-FILE RECORD AT END GO TO CLOSE-UNSORT.
           DISPLAY STU-REC.
           GO TO READ-UNSORT.
       CLOSE-UNSORT.
           OPEN INPUT SORT-FILE.
           DISPLAY UL.
           DISPLAY "                  DATA IN SORTED FORM".
           DISPLAY UL.
           DISPLAY "REG   NAME                             COURSE
      -    "YEAR".
           DISPLAY DL.
       READ-SORT.
           READ SORT-FILE RECORD AT END GO TO CLOSE-SORT.
           MOVE CORRESPONDING SORT-REC TO SHOW-REC.
           DISPLAY SHOW-REC.
           GO TO READ-SORT.
       CLOSE-SORT.
           DISPLAY DL.
           DISPLAY " ".
           CLOSE SORT-FILE.
           STOP RUN.

Write a COBOL program to MULTIPLY TWO MATRICES.


       IDENTIFICATION DIVISION.
       PROGRAM-ID. MATRIX-MULTIPLICATION.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  MATRIXA.
           02 MATA OCCURS 10 TIMES.
              03 A PIC S9(3) OCCURS 10 TIMES.
       01  MATRIXB.
           02 MATB OCCURS 10 TIMES.
              03 B PIC S9(3) OCCURS 10 TIMES.
       01  MATRIXC.
           02 MATC OCCURS 10 TIMES.
              03 C PIC S9(3) OCCURS 10 TIMES.
       01  E-VAL   PIC -ZZ9.
       01  I       PIC 99.
       01  J       PIC 99.
       01  K       PIC 99.
       01  RW      PIC 99.
       01  RC      PIC 99.
       01  CL      PIC 99.
       PROCEDURE DIVISION.
       MAIN-PARA.
           DISPLAY (01 01) ERASE.
           DISPLAY (02 10) "Enter the Order of the Matices".
           DISPLAY (03 10) " I-Matirx : Rows : ".
           DISPLAY (03 31) "Columns : ".
           ACCEPT (03 28) RW.
           ACCEPT (03 41) RC.
           DISPLAY (04 10) "II-Matirx : Rows : ".
           DISPLAY (04 31) "Columns : ".
           DISPLAY (04 28) RC.
           ACCEPT (04 41) CL.
           
           DISPLAY (06 10) "Enter the elements of:".
           DISPLAY (07 10) "First Matrix ".
           DISPLAY (07 50) "Second Matrix".
           MOVE 09 TO LIN.
           MOVE 10 TO COL.
           PERFORM READ-A1 VARYING I FROM 1 BY 1 UNTIL I > RW.
           MOVE 08 TO LIN.
           MOVE 50 TO COL.
           PERFORM READ-B1 VARYING I FROM 1 BY 1 UNTIL I > RC.
           PERFORM COMPUTE-PARA VARYING I FROM 1 BY 1 UNTIL I > RW
                   AFTER J FROM 1 BY 1 UNTIL J > CL.
           ADD 2 TO LIN.
           MOVE 10 TO COL.
           DISPLAY (LIN, 10) "Multiplication of the Matrices".
           DISPLAY (LIN + 1, 10) "------------------------------".
           ADD 2 TO LIN.
           PERFORM DISP-C1 VARYING I FROM 1 BY 1 UNTIL I > RW.
           DISPLAY (LIN, 10) "==============================".
           STOP RUN.
       READ-A1.
           PERFORM READ-A VARYING J FROM 1 BY 1 UNTIL J > RC.
           ADD 1 TO LIN.
           MOVE 10 TO COL.
       READ-A.
           ACCEPT (LIN, COL) A(I J).
           ADD 5 TO COL.
       READ-B1.
           PERFORM READ-B VARYING J FROM 1 BY 1 UNTIL J > CL.
           ADD 1 TO LIN.
           MOVE 50 TO COL.
       READ-B.
           ACCEPT (LIN, COL) B(I J).
           ADD 5 TO COL.
       COMPUTE-PARA.
           MOVE 0 TO C(I J).
           PERFORM MULTI-PARA VARYING K FROM 1 BY 1 UNTIL K > RC.
       MULTI-PARA.
           COMPUTE C(I J) = C(I J) + A(I K) * B(K J).           
       DISP-C1.
           PERFORM DISP-C VARYING J FROM 1 BY 1 UNTIL J > CL.
           ADD 1 TO LIN.
           MOVE 10 TO COL.
       DISP-C.
           MOVE C(I J) TO E-VAL.
           DISPLAY (LIN, COL) E-VAL.
           ADD 5 TO COL.

Write a COBOL program to ADD TWO MATRICES.


       IDENTIFICATION DIVISION.
       PROGRAM-ID. MATRIX-ADDITION.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  MATRIXA.
           02 MATA OCCURS 10 TIMES.
              03 A PIC S9(3) OCCURS 10 TIMES.
       01  MATRIXB.
           02 MATB OCCURS 10 TIMES.
              03 B PIC S9(3) OCCURS 10 TIMES.
       01  MATRIXC.
           02 MATC OCCURS 10 TIMES.
              03 C PIC S9(3) OCCURS 10 TIMES.
       01  E-VAL   PIC -ZZ9.
       01  I       PIC 99.
       01  J       PIC 99.
       01  RW      PIC 99.
       01  CL      PIC 99.
       PROCEDURE DIVISION.
       MAIN-PARA.
           DISPLAY (01 01) ERASE.
           DISPLAY (02 10) "Enter the Order of the Matices".
           DISPLAY (03 10) "Rows : ".
           DISPLAY (03 20) "Columns : ".
           ACCEPT (03 17) RW.
           ACCEPT (03 30) CL.
           DISPLAY (05 10) "Enter the elements of:".
           DISPLAY (06 10) "First Matrix ".
           DISPLAY (06 50) "Second Matrix".
           MOVE 08 TO LIN.
           MOVE 10 TO COL.
           PERFORM READ-A1 VARYING I FROM 1 BY 1 UNTIL I > RW.
           MOVE 08 TO LIN.
           MOVE 50 TO COL.
           PERFORM READ-B1 VARYING I FROM 1 BY 1 UNTIL I > RW.
           PERFORM COMPUTE-PARA VARYING I FROM 1 BY 1 UNTIL I > RW
                   AFTER J FROM 1 BY 1 UNTIL J > CL.
           ADD 2 TO LIN.
           MOVE 10 TO COL.
           DISPLAY (LIN, 10) "Sum of the Matrices".
           DISPLAY (LIN + 1, 10) "-------------------".
           ADD 2 TO LIN.
           PERFORM DISP-C1 VARYING I FROM 1 BY 1 UNTIL I > RW.
           DISPLAY (LIN, 10) "===================".
           STOP RUN.
       READ-A1.
           PERFORM READ-A VARYING J FROM 1 BY 1 UNTIL J > CL.
           ADD 1 TO LIN.
           MOVE 10 TO COL.
       READ-A.
           ACCEPT (LIN, COL) A(I J).
           ADD 5 TO COL.
       READ-B1.
           PERFORM READ-B VARYING J FROM 1 BY 1 UNTIL J > CL.
           ADD 1 TO LIN.
           MOVE 50 TO COL.
       READ-B.
           ACCEPT (LIN, COL) B(I J).
           ADD 5 TO COL.
       COMPUTE-PARA.
           COMPUTE C(I J) = A(I J) + B(I J).
       DISP-C1.
           PERFORM DISP-C VARYING J FROM 1 BY 1 UNTIL J > CL.
           ADD 1 TO LIN.
           MOVE 10 TO COL.
       DISP-C.
           MOVE C(I J) TO E-VAL.
           DISPLAY (LIN, COL) E-VAL.
           ADD 5 TO COL.

A sequential file contains records of consumers of a Telecom Services having the following structure: Consumer Number, Consumer Name, Name of Exchange, Previous Meter Reading and Current Meter Reading(Give appropriate picture clauses). Write a COBOL program to print Telephone Bill for each consumer in a neat format


      *
      *   A sequential file contains records of consumers of a
      *   Telecom Services having the following structure:
      *   Consumer Number,
      *   Consumer Name,
      *   Name of Exchange,
      *   Previous Meter Reading and
      *   Current Meter Reading (Give appropriate picture clauses).
      *
      *   Write a COBOL program to print Telephone Bill
      *   for each consumer in a neat format according to the
      *   following slab:
      *
      *   Slab   Consumption   Rate/Unit(in Rs.)   Telehpone Rent
      *
      *    I      First 250        @ 0.80             Rs. 250
      *    II     Next 600         @ 1.00             Rs. 300
      *    III    Balance          @ 1.20             Rs. 500
      *
       IDENTIFICATION DIVISION.
       PROGRAM-ID. TELE-BILL.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT TELE-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  TELE-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "TELE.DAT"
           DATA RECORD IS TELE-REC.
       01  TELE-REC.
           02 CNO      PIC 9(4).
           02 NAME     PIC X(20).
           02 EXC      PIC X(15).
           02 PRE-READ PIC 9(6).
           02 CUR-READ PIC 9(6).
       WORKING-STORAGE SECTION.
       01  CONSUM      PIC 9(6).
       01  E-CONSUM    PIC Z(5)9.
       01  E-CNO       PIC ZZ9.
       01  E-PRE-READ  PIC Z(5)9.
       01  E-CUR-READ  PIC Z(5)9.
       01  RENT        PIC 9(5).
       01  E-RENT      PIC Z(4)9.
       01  CALL-CHARGE PIC 9(5)V99.
       01  E-CC        PIC Z(4)9.99.
       01  BILL-AMT    PIC Z(5).99.
       01  PAUSE       PIC X.
       PROCEDURE DIVISION.
       OPEN-PARA.
           OPEN INPUT TELE-FILE.
       PROCESS-PARA.
           DISPLAY (01 01) ERASE.
           READ TELE-FILE RECORD AT END GO TO CLOSE-PARA.
           COMPUTE CONSUM = CUR-READ - PRE-READ.
           IF CONSUM > 850
              MOVE 500 TO RENT
              COMPUTE CALL-CHARGE = 800 + (CONSUM - 850) * 1.20
           ELSE
              IF CONSUM > 250
                 MOVE 300 TO RENT
                 COMPUTE CALL-CHARGE = 200 + (CONSUM - 250) * 1.00
              ELSE
                 MOVE 250 TO RENT
                 COMPUTE CALL-CHARGE = CONSUM * 0.80.
           MOVE CALL-CHARGE TO E-CC.
           COMPUTE BILL-AMT = RENT + CALL-CHARGE.
           PERFORM DISPLAY-PARA.
           ACCEPT PAUSE.
           GO TO PROCESS-PARA.
       CLOSE-PARA.
           CLOSE TELE-FILE.
           STOP RUN.
       DISPLAY-PARA.
           MOVE CNO TO E-CNO.
           MOVE PRE-READ TO E-PRE-READ.
           MOVE CUR-READ TO E-CUR-READ.
           MOVE CONSUM TO E-CONSUM.
           MOVE RENT TO E-RENT.
           DISPLAY "-----------------------------------------------".
           DISPLAY "               Telephone Bill ".
           DISPLAY "-----------------------------------------------".
           DISPLAY "          Consumer No : " E-CNO.
           DISPLAY "                 Name : " NAME.
           DISPLAY "        Exchange Name : " EXC.
           DISPLAY " ".
           DISPLAY "     ------------------------------------".
           DISPLAY "      Current Reading : " E-CUR-READ.
           DISPLAY "     Previous Reading : " E-PRE-READ.
           DISPLAY "     ------------------------------------".
           DISPLAY "          Consumption : " E-CONSUM.
           DISPLAY " ".
           DISPLAY "                 Rent : Rs. " E-RENT.
           DISPLAY "         Call Charges : Rs. " E-CC.
           DISPLAY "     ------------------------------------".
           DISPLAY "          Bill Amount : Rs. " BILL-AMT.
           DISPLAY "===============================================".


A student file contain the marks of students scored in various subjects in a class. Each record contain Register Number, Name of Student and Marks scored for Subject1, Subject2 and Subject3(maximum marks 100). Write a COBOL program to prepare a Rank List.


      *
      *   A student file contain the marks of students scored
      *   in various subjects in a class. Each record contain
      *   Register Number, Name of Student and Marks scored for
      *   Subject1, Subject2 and Subject3(maximum marks 100).
      *
      *   Write a COBOL program to prepare a Rank List.
      *
       IDENTIFICATION DIVISION.
       PROGRAM-ID. RANKING.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT STU-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
           SELECT TOT-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
           SELECT WORK-FILE ASSIGN TO DISK.
           SELECT RANK-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  STU-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "MARK.DAT"
           DATA RECORD IS STU-REC.
       01  STU-REC.
           02 REGNO PIC 9(3).
           02 NAME  PIC X(20).
           02 M1    PIC 9(3).
           02 M2    PIC 9(3).
           02 M3    PIC 9(3).
       FD  TOT-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "TOTAL.DAT"
           DATA RECORD IS TOT-REC.
       01  TOT-REC.
           02 REGNO PIC 9(3).
           02 NAME  PIC X(20).
           02 M1    PIC 9(3).
           02 M2    PIC 9(3).
           02 M3    PIC 9(3).
           02 TOTAL PIC 9(3).
       SD  WORK-FILE
           DATA RECORD IS WORK-REC.
       01  WORK-REC.
           02 REGNO PIC 9(3).
           02 NAME  PIC X(20).
           02 M1    PIC 9(3).
           02 M2    PIC 9(3).
           02 M3    PIC 9(3).
           02 TOTAL PIC 9(3).
       FD  RANK-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "RANK.DAT"
           DATA RECORD IS RANK-REC.
       01  RANK-REC.
           02 REGNO   PIC 9(3).
           02 NAME    PIC X(20).
           02 M1      PIC 9(3).
           02 M2      PIC 9(3).
           02 M3      PIC 9(3).
           02 TOTAL   PIC 9(3).
           02 RANK    PIC 9(3).
       WORKING-STORAGE SECTION.
       01  PRE-TOTAL  PIC 9(3) VALUE 0.
       01  T-RANK     PIC 9(3) VALUE 0.
       01  SHOW-REC.
           02 REGNO   PIC ZZ9.
           02 FILLER  PIC X(2).
           02 NAME    PIC X(20).
           02 FILLER  PIC X(2).
           02 M1      PIC ZZ9.
           02 FILLER  PIC X(2).
           02 M2      PIC ZZ9.
           02 FILLER  PIC X(2).
           02 M3      PIC ZZ9.
           02 FILLER  PIC X(2).
           02 TOTAL   PIC ZZ9.
           02 FILLER  PIC X(2).
           02 RANK    PIC ZZ9.
       PROCEDURE DIVISION.
       TOT-PARA.
           OPEN INPUT STU-FILE
                OUTPUT TOT-FILE.
       READMARK-PARA.
           READ STU-FILE RECORD INTO TOT-REC
                AT END GO TO CLOSE-STU-PARA.
           COMPUTE TOTAL OF TOT-REC = M1 OF TOT-REC +
                                      M2 OF TOT-REC +
                                      M3 OF TOT-REC.
           WRITE TOT-REC.
           GO TO READMARK-PARA.
       CLOSE-STU-PARA.
           CLOSE STU-FILE TOT-FILE.
       SORT-PARA.
           SORT WORK-FILE ON DESCENDING KEY TOTAL OF WORK-REC
           USING TOT-FILE
           GIVING RANK-FILE.
       OPEN-PARA.
           OPEN I-O RANK-FILE.
       READ-PARA.
           READ RANK-FILE RECORD AT END GO TO CLOSE-PARA.
           IF PRE-TOTAL NOT = TOTAL OF RANK-REC
              COMPUTE T-RANK = T-RANK + 1
              MOVE TOTAL OF RANK-REC TO PRE-TOTAL.
           MOVE T-RANK TO RANK OF RANK-REC.
           REWRITE RANK-REC.
           GO TO READ-PARA.
       CLOSE-PARA.
           CLOSE RANK-FILE.
           OPEN INPUT RANK-FILE.
           DISPLAY "--------------------------------------------------".
           DISPLAY "                   RANK LIST".
           DISPLAY "--------------------------------------------------".
           DISPLAY "REG  NAME                   M1   M2   M3  TOT RANK".
           DISPLAY "==================================================".
       READRANK-PARA.
           READ RANK-FILE RECORD AT END GO TO CLOSE-RANK-PARA.
           MOVE CORRESPONDING RANK-REC TO SHOW-REC.
           DISPLAY SHOW-REC.
           GO TO READRANK-PARA.
       CLOSE-RANK-PARA.
           CLOSE RANK-FILE.
           DISPLAY "==================================================".
           DISPLAY " ".
           STOP RUN.

A sequential file contains records of consumers of an electricity board having the following structure: Consumer Number, Name of Consumer, Previous Meter Reading and Current Meter Reading(give appropriate picture clauses). Write a COBOL program to print the Electricity Bill for each consumer in a neat format .


      *
      *   A sequential file contains records of consumers of an
      *   electricity board having the following structure:
      *   Consumer Number,
      *   Name of Consumer,
      *   Previous Meter Reading and
      *   Current Meter Reading (give appropriate picture clauses).
      *
      *   Write a COBOL program to print the Electricity Bill
      *   for each consumer in a neat format according to the
      *   following slab:
      *
      *       Consumption     Rate/Unit(in Rs.)
      *           < 50             @ 1.00
      *         50 - 100           @ 1.25
      *           > 100            @ 1.50
      *
       IDENTIFICATION DIVISION.
       PROGRAM-ID. ELECTRICITY-BILL.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT ELE-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  ELE-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "ELE.DAT"
           DATA RECORD IS ELE-REC.
       01  ELE-REC.
           02 CNO      PIC 9(4).
           02 NAME     PIC X(20).
           02 PRE-READ PIC 9(6).
           02 CUR-READ PIC 9(6).
       WORKING-STORAGE SECTION.
       01  CONSUM      PIC 9(4).
       01  E-CONSUM    PIC Z(3)9.
       01  E-CNO       PIC Z(3)9.
       01  E-PRE-READ  PIC Z(5)9.
       01  E-CUR-READ  PIC Z(5)9.
       01  BILL-AMT    PIC Z(5).99.
       01  PAUSE       PIC X.
       PROCEDURE DIVISION.
       OPEN-PARA.
           OPEN INPUT ELE-FILE.
       PROCESS-PARA.
           DISPLAY (01 01) ERASE.
           READ ELE-FILE RECORD AT END GO TO CLOSE-PARA.
           COMPUTE CONSUM = CUR-READ - PRE-READ.
           IF CONSUM > 100
              COMPUTE BILL-AMT = CONSUM * 1.50
           ELSE
              IF CONSUM > 50
                 COMPUTE BILL-AMT = CONSUM * 1.25
              ELSE
                 COMPUTE BILL-AMT = CONSUM * 1.00.
           PERFORM DISPLAY-PARA.
           ACCEPT PAUSE.
           GO TO PROCESS-PARA.
       CLOSE-PARA.
           CLOSE ELE-FILE.
           STOP RUN.
       DISPLAY-PARA.
           MOVE CNO TO E-CNO.
           MOVE PRE-READ TO E-PRE-READ.
           MOVE CUR-READ TO E-CUR-READ.
           MOVE CONSUM TO E-CONSUM.
           DISPLAY "-----------------------------------------------".
           DISPLAY "               Electricity Bill ".
           DISPLAY "-----------------------------------------------".
           DISPLAY "          Consumer No.: " E-CNO.
           DISPLAY "                 Name : " NAME.
           DISPLAY " ".
           DISPLAY "     ----------------------------------".
           DISPLAY "      Current Reading : " E-CUR-READ.
           DISPLAY "     Previous Reading : " E-PRE-READ.
           DISPLAY " ".
           DISPLAY "          Consumption : " E-CONSUM.
           DISPLAY "     ----------------------------------".
           DISPLAY "          Bill Amount : " BILL-AMT.
           DISPLAY "===============================================".


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.

Sample MERGE program using COBOL


       IDENTIFICATION DIVISION.
       PROGRAM-ID. MERGING-OF-SEQUENTIAL-FILES.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT STU1-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
           SELECT STU2-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
           SELECT OUT-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
           SELECT WORK-FILE ASSIGN TO DISK.
       DATA DIVISION.
       FILE SECTION.
       FD  STU1-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "LIST1.DAT"
           DATA RECORD IS STU1-REC.
       01  STU1-REC.
           02 REGNO1   PIC 999.
           02 NAME1    PIC X(10).
           02 YOA1     PIC 9999.
       FD  STU2-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "LIST2.DAT"
           DATA RECORD IS STU2-REC.
       01  STU2-REC.
           02 REGNO2   PIC 999.
           02 NAME2    PIC X(10).
           02 YOA2     PIC 9999.
       FD  OUT-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "MLIST.DAT"
           DATA RECORD IS OUT-REC.
       01  OUT-REC.
           02 OREGNO   PIC 999.
           02 ONAME    PIC X(10).
           02 OYOA     PIC 9999.
       SD  WORK-FILE
           DATA RECORD IS WORK-REC.
       01  WORK-REC.
           02 WREGNO   PIC 999.
           02 WNAME    PIC X(10).
           02 WYOA     PIC 9999.
       PROCEDURE DIVISION.
       MAIN-PARA.
           MERGE WORK-FILE
                ON DESCENDING KEY WYOA
                ON ASCENDING KEY WNAME
                USING STU1-FILE STU2-FILE
                GIVING OUT-FILE.
       OPEN-PARA.
           OPEN INPUT OUT-FILE.
           DISPLAY "------------------------------------".
           DISPLAY "   MERGED RECORDS".
           DISPLAY "------------------------------------".
       READ-PARA.
           READ OUT-FILE RECORD AT END GO TO CLOSE-PARA.
           DISPLAY OUT-REC.
           GO TO READ-PARA.
       CLOSE-PARA.
           DISPLAY "------------------------------------".
           DISPLAY " ".
           CLOSE OUT-FILE.
           STOP RUN.

Sample Sorting program using COBOL


       IDENTIFICATION DIVISION.
       PROGRAM-ID. SORTING-OF-SEQUENTIAL-FILE.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT STU-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
           SELECT OUT-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
           SELECT WORK-FILE ASSIGN TO DISK.
       DATA DIVISION.
       FILE SECTION.
       FD  STU-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "NAMELIST.DAT"
           DATA RECORD IS STU-REC.
       01  STU-REC.
           02 REGNO   PIC 999.
           02 NAME    PIC X(10).
           02 YOA     PIC 9999.
       FD  OUT-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "SORTLIST.DAT"
           DATA RECORD IS OUT-REC.
       01  OUT-REC.
           02 OREGNO   PIC 999.
           02 ONAME    PIC X(10).
           02 OYOA     PIC 9999.
       SD  WORK-FILE
           DATA RECORD IS WORK-REC.
       01  WORK-REC.
           02 WREGNO   PIC 999.
           02 WNAME    PIC X(10).
           02 WYOA     PIC 9999.
       PROCEDURE DIVISION.
       MAIN-PARA.
           SORT WORK-FILE
                ON DESCENDING KEY WYOA
                ON ASCENDING KEY WNAME
                USING STU-FILE
                GIVING OUT-FILE.
           STOP RUN.

Preparation of Mark List by reading data from a Student File (Line Sequential)


       IDENTIFICATION DIVISION.
       PROGRAM-ID. STUDENT-FILE-MARKLIST-PREPARATION.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT STU-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  STU-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "STU.DAT"
           DATA RECORD IS STU-REC.
       01  STU-REC.
           02 REGNO   PIC 999.
           02 NAME    PIC X(30).
           02 M1      PIC 999.
           02 M2      PIC 999.
           02 M3      PIC 999.
       WORKING-STORAGE SECTION.
       01  TM         PIC 999.
       01  EDT-REC.
           02 EREGNO  PIC ZZ9.
           02 ENAME   PIC X(30).
           02 EM1     PIC ZZ9.
           02 EM2     PIC ZZ9.
           02 EM3     PIC ZZ9.
           02 ETM     PIC ZZ9.
           02 RESULT  PIC X(20).
       01  SL         PIC X(40) VALUE ALL "-".
       01  DL         PIC X(40) VALUE ALL "=".
       01  PAUSE      PIC X.
       PROCEDURE DIVISION.
       MAIN-PARA.
           PERFORM OPEN-PARA.
       READ-PARA.
           READ STU-FILE RECORD AT END GO TO CLOSE-PARA.
           COMPUTE TM = M1 + M2 + M3.
           IF TM NOT < 240
              MOVE "Distinction" TO RESULT
           ELSE IF TM NOT < 180
                   MOVE "First Class" TO RESULT
                ELSE IF TM NOT < 150
                        MOVE "Second Class" TO RESULT
                     ELSE
                        MOVE "Failed" TO RESULT.
           MOVE REGNO TO EREGNO.
           MOVE NAME TO ENAME.
           MOVE M1 TO EM1.
           MOVE M2 TO EM2.
           MOVE M3 TO EM3.
           MOVE TM TO ETM.
           DISPLAY (01 01) SPACES.
           DISPLAY (02 01) SL.
           DISPLAY (03 12) "M A R K   L I S T".
           DISPLAY (04 01) DL.
           DISPLAY (05 01) "   Register No : " EREGNO.
           DISPLAY (06 01) "          Name : " ENAME.
           DISPLAY (07 01) "      Marks in  ".
           DISPLAY (08 01) "     Subject-1 : " EM1.
           DISPLAY (09 01) "     Subject-2 : " EM2.
           DISPLAY (10 01) "     Subject-3 : " EM3.
           DISPLAY (12 01) "   Total Marks : " ETM.
           DISPLAY (14 01) "        Result : " RESULT.
           DISPLAY (16 01) DL.
           ACCEPT PAUSE.
           GO TO READ-PARA.
       OPEN-PARA.
           OPEN INPUT STU-FILE.
       CLOSE-PARA.
           DISPLAY " ".
           CLOSE STU-FILE.
           STOP RUN.

Reading a Line Sequential File and displaying the content in a neat format


       IDENTIFICATION DIVISION.
       PROGRAM-ID. READING-LINE-SEQUENTIAL-FILE.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT STU-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  STU-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "STU.DAT"
           DATA RECORD IS STU-REC.
       01  STU-REC.
           02 REGNO   PIC 999.
           02 NAME    PIC X(30).
           02 M1      PIC 999.
           02 M2      PIC 999.
           02 M3      PIC 999.
       WORKING-STORAGE SECTION.
       01  TM         PIC 999.
       01  EDT-REC.
           02 EREGNO  PIC ZZ9.
           02 FILLER  PIC XX VALUE SPACES.
           02 ENAME   PIC X(30).
           02 EM1     PIC ZZ9.
           02 FILLER  PIC XX VALUE SPACES.
           02 EM2     PIC ZZ9.
           02 FILLER  PIC XX VALUE SPACES.
           02 EM3     PIC ZZ9.
           02 FILLER  PIC XX VALUE SPACES.
           02 ETM     PIC ZZ9.
       PROCEDURE DIVISION.
       MAIN-PARA.
           PERFORM OPEN-PARA.
           DISPLAY "----------------------------------------------------
      -    "----".
           DISPLAY "                        MARK LIST".
           DISPLAY "----------------------------------------------------
      -    "----".
           DISPLAY "RNO  NAME                           M1   M2   M3  TO
      -    "TAL".
           DISPLAY "====================================================
      -    "====".
       READ-PARA.
           READ STU-FILE RECORD AT END GO TO CLOSE-PARA.
           COMPUTE TM = M1 + M2 + M3.
           MOVE REGNO TO EREGNO.
           MOVE NAME TO ENAME.
           MOVE M1 TO EM1.
           MOVE M2 TO EM2.
           MOVE M3 TO EM3.
           MOVE TM TO ETM.
           DISPLAY EDT-REC.
           GO TO READ-PARA.
       OPEN-PARA.
           OPEN INPUT STU-FILE.
       CLOSE-PARA.
           DISPLAY "====================================================
      -    "====".
           DISPLAY " ".
           CLOSE STU-FILE.
           STOP RUN.

Creation of Line Sequential - Student File with records having REGNO, NAME and MARKS OF THREE SUBJECTS.


       IDENTIFICATION DIVISION.
       PROGRAM-ID. STUDENT-FILE-SEQUENTIAL-FILE.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT STU-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  STU-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "STU.DAT"
           DATA RECORD IS STU-REC.
       01  STU-REC.
           02 REGNO   PIC 999.
           02 NAME    PIC X(30).
           02 M1      PIC 999.
           02 M2      PIC 999.
           02 M3      PIC 999.
       WORKING-STORAGE SECTION.
       77  NOS        PIC 99.
       PROCEDURE DIVISION.
       MAIN-PARA.
           PERFORM OPEN-PARA.
           DISPLAY "Enter the Number of Students : ".
           ACCEPT NOS.
           PERFORM GET-DATA NOS TIMES.
           PERFORM CLOSE-PARA.
           STOP RUN.
       OPEN-PARA.
           OPEN OUTPUT STU-FILE.
       GET-DATA.
           DISPLAY "Enter the Register  No : ".
           ACCEPT REGNO.
           DISPLAY "Enter the Name : ".
           ACCEPT NAME.
           DISPLAY "Three Marks : ".
           ACCEPT M1.
           ACCEPT M2.
           ACCEPT M3.
           WRITE STU-REC.
       CLOSE-PARA.
           CLOSE STU-FILE.