JCW2
asked on
0 Student Schools in COBOL
I'm trying to print names of schools and their students to a file. JCL is involved, but I think I have that correct. The file I'm looking at is just using the schools with 0 students. Where am I going wrong?
*---------------------------------------------*
*- The identification division contains the -*
*- name (PROGRAM-ID) of the program as well -*
*- as some other identifying information. -*
*---------------------------------------------*
IDENTIFICATION DIVISION.
PROGRAM-ID. COBOL.
AUTHOR. J. Colt Wright
*---------------------------------------------*
*- The environment division contains the -*
*- input-output section where files are -*
*- initialized -*
*---------------------------------------------*
ENVIRONMENT DIVISION.
*
INPUT-OUTPUT SECTION.
FILE-CONTROL.
*---------------------------------------------*
*- The SELECT statement associates a file -*
*- used by the program (in this case, -*
*- Output-File is the file name) with the -*
*- DDName it will be referred to in the JCL -*
*- (in this case, PGM01 is the DDName). -*
*- The following SELECT statement tells the -*
*- program that the following line will be -*
*- present in the JCL and the dataset member -*
*- referenced in the JCL should be used for -*
*- Output-File -*
*- PGMO1 DD DSN=dataset.member -*
*---------------------------------------------*
SELECT Output-File ASSIGN TO PGMO1.
SELECT High-File ASSIGN TO PGMO2.
SELECT Input-File ASSIGN TO PGMI1.
SELECT Zero-File ASSIGN TO PGM20.
*---------------------------------------------*
*- The SELECT statement is used to associate -*
*- dataset members both for input and for -*
*- output. -*
*---------------------------------------------*
*
*---------------------------------------------*
*- The data division describes the data used -*
*- by the program. -*
*---------------------------------------------*
DATA DIVISION.
*
FILE SECTION.
*---------------------------------------------*
*- The following FD entry tells the -*
*- program how to write a line to the output -*
*- file. There can be several FD entries -*
*- per output file. -*
*- In this example, the line consists of -*
*- 25 columns for the school name, 3 blank -*
*- columns, then an up to three digit school -*
*- number. The last 224 columns of the line -*
*- (record) are left blank. -*
*---------------------------------------------*
FD Output-File RECORDING MODE F.
01 Line-Out.
05 SchoolN-Out PIC X(25).
05 Filler PIC X(3).
05 SNumber-Out PIC ZZ9.
05 Filler PIC X(224).
*
FD High-File RECORDING MODE F.
01 High-Out.
05 HSchoolN-Out PIC X(25).
05 Filler PIC X(3).
05 HSNumber-Out PIC ZZ9.
05 Filler PIC X(224).
*
FD Zero-File RECORDING MODE F.
01 Zero-Out.
05 ZSchoolN-Out PIC X(25).
05 Filler PIC X(3).
05 ZSNumber-Out PIC ZZ9.
05 Filler PIC X(224).
*
*---------------------------------------------*
*- FD entries exist for input files too, and -*
*- define how data read from an input file -*
*- will be organized. -*
*- In this case, the input file consists of -*
*- a 3-digit field called SNumber-In and a -*
*- 50-character field called SchoolN-In. -*
*- The last 27 characters of the line are -*
*- not important to this program. -*
*---------------------------------------------*
FD Input-File RECORDING MODE F.
01 Line-In.
05 SNumber-In PIC 999.
05 SchoolN-In PIC X(50).
05 Filler PIC X(27).
*
*---------------------------------------------*
*- The working-storage section contains -*
*- variables for use in the program. -*
*---------------------------------------------*
WORKING-STORAGE SECTION.
01 FLAGS.
05 LASTREC PIC X VALUE SPACE.
88 LAST-REC VALUE "N".
01 Header.
05 PIC X(28) VALUE 'School Name'.
05 PIC X(227) VALUE 'Number of Participants'.
*---------------------------------------------*
*- The procedure division contains the code -*
*- divided into several procedures. -*
*---------------------------------------------*
PROCEDURE DIVISION.
OPEN-FILES.
*---------------------------------------------*
*- Files are opened as either input or output-*
*---------------------------------------------*
OPEN INPUT Input-File.
OPEN OUTPUT Output-File.
OPEN OUTPUT High-File.
OPEN OUTPUT Zero-File.
*
READ-NEXT-RECORD.
*---------------------------------------------*
*- The following two lines move the contents -*
*- of the header to Line-Out, which is -*
*- associated with Output-File (refer back -*
*- to the FD entry if needed). -*
*- Line-Out is then written, which means -*
*- the contents are added to the contents of -*
*- Output-File. -*
*---------------------------------------------*
MOVE Header TO Line-Out.
Write Line-Out.
*---------------------------------------------*
*- The following two lines write a blank line-*
*- to Output-File. -*
*---------------------------------------------*
MOVE SPACES TO Line-Out.
WRITE Line-Out.
*---------------------------------------------*
*- The next lines write data to High-File -*
*---------------------------------------------*
MOVE Header TO High-Out.
Write High-Out.
MOVE SPACES TO High-Out.
WRITE High-Out.
MOVE Header TO Zero-Out.
Write Zero-Out.
MOVE SPACES TO Zero-Out.
WRITE Zero-Out.
*---------------------------------------------*
*- The next block of code iterates until the -*
*- variable LAST-REC is true. -*
*- The loop calls (performs) two procedures. -*
*---------------------------------------------*
PERFORM UNTIL LAST-REC
PERFORM READ-RECORD
PERFORM WRITE-RECORD
END-PERFORM.
*
*---------------------------------------------*
*- The READ-RECORD procedure reads a line -*
*- from Input-File (the contents are saved -*
*- in LINE-IN, see the corresponding FD -*
*- entry above). -*
*- When the end of the file is reached, -*
*- the variable LAST-REC is set to true. -*
*---------------------------------------------*
READ-RECORD.
READ Input-File
AT END SET LAST-REC TO TRUE
PERFORM CLOSE-STOP
END-READ.
*
*---------------------------------------------*
*- The WRITE-RECORD procedure writes data to -*
*- both of the output files. Data is written-*
*- to Output-File every time the procedure -*
*- is called and data is written to High-File-*
*- only if the SNumber-In value is greater -*
*- than 25. -*
*---------------------------------------------*
WRITE-RECORD.
MOVE SchoolN-In TO SchoolN-Out.
MOVE SNumber-In TO SNumber-Out.
WRITE Line-Out.
IF SNumber-In GREATER THAN 25 THEN
MOVE SchoolN-In TO HSchoolN-Out
MOVE SNumber-In TO HSNumber-Out
WRITE Zero-out
END-IF.
IF SNumber-In IS EQUAL TO 0 THEN
MOVE SchoolN-In TO ZSchoolN-Out
MOVE SNumber-In TO ZSNumber-Out
WRITE High-Out
END-IF.
*
*---------------------------------------------*
*- The CLOSE-STOP procedure closes all input -*
*- and output files and signals the program -*
*- to stop. -*
*---------------------------------------------*
CLOSE-STOP.
CLOSE Input-File.
CLOSE Output-File.
CLOSE High-File.
CLOSE Zero-File.
STOP RUN.
*
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER