IDENTIFICATION DIVISION.
PROGRAM-ID. MonthTable.
* This
program counts the number of students born in each month and
* displays
the result.
ENVIRONMENT
DIVISION.
INPUT-OUTPUT
SECTION.
FILE-CONTROL.
SELECT
StudentFile ASSIGN TO "STUDENTS.DAT"
ORGANIZATION IS LINE SEQUENTIAL.
SELECT
MonthFile ASSIGN TO "MONTH.DAT"
ORGANIZATION IS LINE SEQUENTIAL.
DATA
DIVISION.
FILE
SECTION.
FD
StudentFile.
01
StudentDetails.
02 StudentId PIC 9(7).
02 StudentName.
03
Surname PIC X(8).
03
Initials PIC XX.
02 DateOfBirth.
03
YOBirth PIC 9(4).
03
MOBirth PIC 9(2).
03
DOBirth PIC 9(2).
02 CourseCode PIC X(4).
02 Gender
PIC X.
FD
MonthFile.
01 MonthRec
pic x(20).
WORKING-STORAGE SECTION.
01
EOF-SW PIC X VALUE
"N".
88
END-OF-FILE VALUE
"Y".
01
MonthTable.
05
TableValues.
10
FILLER PIC X(18) VALUE
"January February".
10
FILLER PIC X(18) VALUE
"March April".
10
FILLER PIC X(18) VALUE
"May June".
10
FILLER PIC X(18) VALUE
"July August".
10
FILLER PIC X(18) VALUE
"SeptemberOctober".
10
FILLER PIC X(18) VALUE
"November December".
05
Table-Month-Names REDEFINES TableValues.
10
Month OCCURS 12 TIMES PIC X(9).
01 Count-per-Month.
05
MonthCount OCCURS 12 TIMES PIC 999.
01
MonthSub PIC 999.
01
HeadingLine PIC X(19) VALUE
" Month StudCount".
01
DisplayLine.
05
PrnMonth PIC X(9).
05 FILLER PIC X(4) VALUE SPACES.
05
PrnStudentCount PIC ZZ9.
PROCEDURE
DIVISION.
Begin.
OPEN
INPUT StudentFile, OUTPUT MonthFile
INITIALIZE Count-per-Month
READ
StudentFile
AT
END MOVE "Y" TO EOF-SW
END-READ
PERFORM
UNTIL END-OF-FILE
ADD
1 TO MonthCount(MOBirth)
READ
StudentFile
AT END MOVE "Y" TO EOF-SW
END-READ
END-PERFORM
WRITE
MONTHREC FROM HeadingLine
PERFORM
VARYING MonthSub FROM 1 BY 1 UNTIL MonthSub > 12
MOVE
Month(MonthSub) TO PrnMonth
MOVE
MonthCount(MonthSub) TO PrnStudentCount
WRITE MONTHREC FROM DisplayLine
END-PERFORM
CLOSE
StudentFile
STOP
RUN.