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.

No comments:

Post a comment