Logo 
Search:

Cobol Articles

Submit Article
Home » Articles » Cobol » Homework HelpRSS Feeds

PROGRAM TO SORT THE RECORDS OF FILE

Posted By: Louis Evans     Category: Cobol     Views: 4519

PROGRAM TO SORT THE RECORDS OF FILE.

Code for PROGRAM TO SORT THE RECORDS OF FILE in Cobol

       IDENTIFICATION DIVISION.
         PROGRAM-ID. SRT.
       ENVIRONMENT DIVISION.
        FILE-CONTROL.
         SELECT IN-FILE ASSIGN TO "INPUT.TXT"
         ORGANIZATION IS LINE SEQUENTIAL.

         SELECT SORT-FILE ASSIGN TO SYSWORK.

         SELECT OUT-FILE ASSIGN TO "SORT.TXT"
         ORGANIZATION IS LINE SEQUENTIAL.
         
       DATA DIVISION.
        FILE SECTION.
          FD IN-FILE
              LABEL RECORDS ARE STANDARD.
          01 IN-REC.
           05 ROLLNO PIC 99.
           05 NAME1  PIC X(10).

          SD SORT-FILE.
          01 SORT-REC.
           05 NO1 PIC 99.
           05     PIC X(10).

          FD OUT-FILE
              LABEL RECORDS ARE STANDARD.
          01 OUT-REC.
           05 ROLLNO1 PIC 99.
           05 NAME2  PIC X(10).
         
        WORKING-STORAGE SECTION.
         01 EOF PIC X VALUE 'N'.

       PROCEDURE DIVISION.
         BEGIN.
           SORT SORT-FILE
              ON ASCENDING KEY NO1
                INPUT  PROCEDURE PARA1
                GIVING OUT-FILE
            STOP RUN.

         PARA1.
           OPEN INPUT IN-FILE
           PERFORM UNTIL EOF='Y'
             READ IN-FILE
               AT END MOVE 'Y' TO EOF
               NOT AT END
                 MOVE IN-REC TO SORT-REC
                 RELEASE SORT-REC
             END-READ
           END-PERFORM
           CLOSE IN-FILE.


************************************ OUTPUT *****************************
 INPUT.TXT
          01APURVA
          04NILAY
          03KETAN

 SORT.TXT
          01APURVA
          03KETAN
          04NILAY
  
Share: 


Didn't find what you were looking for? Find more on PROGRAM TO SORT THE RECORDS OF FILE Or get search suggestion and latest updates.

Louis Evans
Louis Evans author of PROGRAM TO SORT THE RECORDS OF FILE is from London, United Kingdom.
 
View All Articles

 
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!