Solved

0 Student Schools in COBOL

Posted on 2010-11-08
2
580 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
2 Comments
 
LVL 6

Accepted Solution

by:
brb6708 earned 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This is about my first experience with programming Arduino.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now