COBOL Program to sort a masterfile and produce a new file with example

3 Comments | 2836 Views | Post by: Admin | Tags: COBOL Program to sort a masterfile and produce a new file with example, COBOL Program COBOL example program


Sorts the student masterfile (sorted on ascending Student Id) and produces a new file, sorted on ascending student name, containing only the records of male students. To test the program download Students.Dat




      $ SET SOURCEFORMAT"FREE"
IDENTIFICATION DIVISION.
PROGRAM-ID.  MaleSort.
AUTHOR.  Michael Coughlan.
* Uses the the SORT and an INPUT PROCEDURE to read
* the student masterfile (sorted on ascending Student Id)
* and from it to produce a file containing only the records of
* male students sorted on ascending student name.
 
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT StudentFile ASSIGN TO "STUDENTS.DAT"
		ORGANIZATION IS LINE SEQUENTIAL.

    SELECT MaleStudentFile ASSIGN TO "MALESTUDS.DAT"
		ORGANIZATION IS LINE SEQUENTIAL.

    SELECT WorkFile ASSIGN TO "WORK.TMP".


DATA DIVISION.
FILE SECTION.
FD StudentFile.
01 StudentRec      PIC X(30).
   88 EndOfFile    VALUE HIGH-VALUES.

FD MaleStudentFile.
01 MaleStudentRec  PIC X(30).

SD WorkFile.
01 WorkRec.
   02 FILLER             PIC 9(7).
   02 WStudentName       PIC X(10).
   02 FILLER             PIC X(12).
   02 WGender            PIC X.
      88 MaleStudent     VALUE "M".


PROCEDURE DIVISION.
Begin.
   SORT WorkFile ON ASCENDING KEY WStudentName
        INPUT PROCEDURE IS GetMaleStudents
        GIVING MaleStudentFile.
   STOP RUN.


GetMaleStudents.
   OPEN INPUT StudentFile
   READ StudentFile
      AT END SET EndOfFile TO TRUE
   END-READ
   PERFORM UNTIL EndOfFile
      MOVE StudentRec TO WorkRec
      IF MaleStudent
         RELEASE WorkRec
      END-IF
      READ StudentFile
        AT END SET EndOfFile TO TRUE
      END-READ 
   END-PERFORM
   CLOSE StudentFile.

 


Post Comments

if you have some suggestion, question, request on COBOL Program to sort a masterfile and produce a new file with example.

Please use the comment box to express your views.

 

Comments:

loading...