Pages

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.

1 comment:

  1. Data following and its understanding and the usage of this data at the right place are not easy for any common men to understand the very much big data. The activewizards.com/: website which provides you the best data scientist for solving up your data understanding problem.

    ReplyDelete