?
Solved

0 Student Schools in COBOL

Posted on 2010-11-08
2
Medium Priority
?
606 Views
Last Modified: 2012-05-10
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.                                 
      *

Open in new window

0
Comment
Question by:JCW2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
brb6708 earned 2000 total points
ID: 34086722
seems as if you meixed up the outfile names (at least the filenames in the write statements do not match the fields in the record...

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                          -------> probably correct: WRITE High-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                          ------> probably correct: WRITE Zero-out
           END-IF.                                  
      *                                      
0
 

Author Closing Comment

by:JCW2
ID: 34090235
That was perfect; thank you.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Make the most of your online learning experience.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question