Solved

cobol programming problem

Posted on 2004-04-15
3
402 Views
Last Modified: 2013-11-25
Hi, im currently writing a sequential file update program for class and I have spent the last 3 hours trying to figure out why it isn't updating correctly. I have3 files. old master file, a new master file and a transaction file. It reads the old master file in and the transaction file in, and it is using the student no as the key to compare. if the student no is smaller than the old master file, it just copies the old master records into the new file, but if it compares it and see's that the student number is greater in the transaction file, it copies fro mthe transaction file to the new master file.

My problem is that, it is skipping the first record of the old master and not copying it over, but copies everything else and it is not adding the transaction records to the new master file. below is my code

//Y18$ JOB (SC067109),MSGCLASS=X,CLASS=A
// EXEC COB2UCG
//COB2.SYSIN DD * >>> COBOL PROGRAM FOLLOWS THIS LINE <<<      
       IDENTIFICATION DIVISION.                                                                                
       PROGRAM-ID. LAB9.                                                                                    
       ENVIRONMENT DIVISION.                                                                            
       INPUT-OUTPUT SECTION.                                                                                
       FILE-CONTROL.                                                                                          
           SELECT TRANSACTION-FILE-IN                                                                    
               ASSIGN TO TRANS.
           SELECT OLD-MASTER-FILE-IN
               ASSIGN TO OLD.                                                              
           SELECT NEW-MASTER-FILE-OUT                                                                    
               ASSIGN TO NEW.                                                                  
       DATA DIVISION.                                                                                      
       FILE SECTION.                                                                                    
       FD  OLD-MASTER-FILE-IN                                                                            
           LABEL RECORDS ARE OMITTED                                                                      
           RECORD CONTAINS 80 CHARACTERS.                                                              
       01  OLD-MASTER-REC-IN.                                                                              
           05  STUDENT-NO-IN                   PIC X(4).                                                
           05  STUDENT-NAME-IN                 PIC X(10).
           05  COURSE-CODE-IN                  PIC X(8).                                      
           05  NUMBER-OF-CREDITS-IN            PIC 99.                                            
           05                                  PIC X(56).                          
       FD  NEW-MASTER-FILE-OUT                                                                            
           LABEL RECORDS ARE OMITTED                                                                      
           RECORD CONTAINS 80 CHARACTERS.                                                              
       01  NEW-MASTER-REC-OUT.                                                                              
           05  STUDENT-NO-OUT                   PIC X(4).                                                
           05  STUDENT-NAME-OUT                 PIC X(10).
           05  COURSE-CODE-OUT                 PIC X(8).                              
           05  NUMBER-OF-CREDITS-OUT            PIC 99.                                            
           05                                  PIC X(56).                          
       FD TRANSACTION-FILE-IN
           LABEL RECORDS ARE OMITTED                                                                      
           RECORD CONTAINS 80 CHARACTERS.
       01  TRANS-REC-IN.
           05  STUDENT-NO-IN                   PIC X(4).                                                
           05  STUDENT-NAME-IN                 PIC X(10).
           05  COURSE-CODE-IN                  PICX (8).                                                                      

           05  NUMBER-OF-CREDITS-IN            PIC 99.                                            
           05  NUMBER-OF-CREDITS-IN            PIC 99.
           05                                  PIC X(56).
       WORKING-STORAGE SECTION.
       01 WORK-AREA.
          05 ARE-THERE-MORE-RECORDS           PIC XXX VALUE "YES".
             88 MORE-RECORDS                          VALUE "YES".
             88 NO-MORE-RECORDS                       VALUE "NO".
       PROCEDURE DIVISION.                                                                              
       0-MAIN-MODULE.  
           PERFORM 1-INITIALIZE
                   UNTIL STUDENT-NO-IN OF TRANS-REC-IN = HIGH-VALUE
                   AND STUDENT-NO-IN OF OLD-MASTER-REC-IN = HIGH-VALUE
           END-READ
           PERFORM 3-TERMINATE
           STOP RUN.  
       1-INITIALIZE.                                                                            
           OPEN INPUT  TRANSACTION-FILE-IN
                       OLD-MASTER-FILE-IN                                                                  
                OUTPUT NEW-MASTER-FILE-OUT
                PERFORM C1-READ-TRANS
                PERFORM C2-READ-OLD-MASTER                                            
       2-COMPARE.
           EVALUATE TRUE
           WHEN STUDENT-NO-IN OF OLD-MASTER-REC-IN
                < STUDENT-NO-IN OF TRANS-REC-IN
                  PERFORM 2-1-COPY-OLD-MASTER
                  PERFORM 2-COMPARE    
           WHEN STUDENT-NO-IN OF TRANS-REC-IN
                > STUDENT-NO-IN OF OLD-MASTER-REC-IN
                PERFORM 2-2-ADD-MASTER
           END-EVALUATE.
       C1-READ-TRANS.
           READ TRANSACTION-FILE-IN
             AT END
                MOVE HIGH-VALUES TO STUDENT-NO-IN OF TRANS-REC-IN
           END-READ.
       C2-READ-OLD-MASTER.
           READ OLD-MASTER-FILE-IN
             AT END
                MOVE HIGH-VALUES TO STUDENT-NO-IN OF OLD-MASTER-REC-IN
             END-READ.
       2-1-COPY-OLD-MASTER.
           WRITE NEW-MASTER-REC-OUT FROM OLD-MASTER-REC-IN
           PERFORM C2-READ-OLD-MASTER.
       2-2-ADD-MASTER.
           MOVE STUDENT-NO-IN OF TRANS-REC-IN TO STUDENT-NO-OUT
           MOVE STUDENT-NAME-IN OF TRANS-REC-IN TO STUDENT-NAME-OUT
           MOVE COURSE-CODE-IN OF TRANS-REC-IN TO COURSE-CODE-OUT
           MOVE NUMBER-OF-CREDITS-IN OF TRANS-REC-IN
                                         TO NUMBER-OF-CREDITS-OUT
           WRITE NEW-MASTER-REC-OUT
           PERFORM C1-READ-TRANS.
       3-TERMINATE.
           CLOSE TRANSACTION-FILE-IN
                 OLD-MASTER-FILE-IN
                 NEW-MASTER-FILE-OUT.                                              
/*
//GO.TRANS  DD *
0009TOMMY   CIS 374104  
0010TON     CIS 374104
0011TOB     CIS 374104
0012TOC     CIS 374104
/*
//GO.NEW   DD SYSOUT=*
//GO.OLD DD * >>> DATA FOLLOWS THIS LINE <<<
0001KEVIN     CIS 374104  
0002TOM       CIS 261004
0003JIMMY     CIS 261704                                        
0004GWBUSH    CIS 261704
0005MOE       CSIS250102
0006LARRY     CSIS250502
0007CURLY     PHED330304
0008ANYONE    PHED330304  
/*
//
//





here is what the results are after i compile
 !! END OF JES SPOOL FILE !!
0002TOM       CIS 261004                                                        
0003JIMMY     CIS 261704                                                        
0004GWBUSH    CIS 261704                                                        
0005MOE       CSIS250102                                                        
0006LARRY     CSIS250502                                                        
0007CURLY     PHED330304                                                        
0008ANYONE    PHED330304                                                        
 !! END OF JES SPOOL FILE !!

thanks
0
Comment
Question by:ysujim
3 Comments
 
LVL 27

Expert Comment

by:Dabas
Comment Utility
Hi ysujim,
>            WHEN STUDENT-NO-IN OF OLD-MASTER-REC-IN
>                 < STUDENT-NO-IN OF TRANS-REC-IN
>                   PERFORM 2-1-COPY-OLD-MASTER
>                   PERFORM 2-COMPARE    
>            WHEN STUDENT-NO-IN OF TRANS-REC-IN
>                 > STUDENT-NO-IN OF OLD-MASTER-REC-IN
>                 PERFORM 2-2-ADD-MASTER

First When compares Master < Student
SEcond When compares Student > Master

Looks to me as if you are comparing the same thing twice?

I thought Cobol had been declared extinct after the year 2000 bug issues it created!
I pity you!

Dabas
0
 
LVL 1

Accepted Solution

by:
MortimerCat earned 125 total points
Comment Utility
I agree with Dabas the second check should be

WHEN STUDENT-NO-IN OF TRANS-REC-IN
             < STUDENT-NO-IN OF OLD-MASTER-REC-IN
               PERFORM 2-2-ADD-MASTER

I fancied a bit of nostalgia, so I tried to solve the missing first record. I came to the conclusion that the data files must be corrupted. Have you made sure the original data is still intact, and has not be overwritten by an earlier version of your program?

I noticed another anomaly, whilst stepping through the program.  When you ran it, did it terminate properly?
You are doing a PERFORM 1-INITIALIZE, which opens the files and starts the whole process. But this is repeated? UNTIL the EOFs have been reached.

When I step through it on paper, it reads and writes the entire master file. The 1-INITIALIZE procedure ends, but because the Transaction file has not been touched, 1-INITIALIZE is PERFORMed again. Finally crashing out because the files are already open.
0
 

Author Comment

by:ysujim
Comment Utility
I understand what is going on now. Thank you all for your help!

Regards,
James
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 …
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 …

771 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

12 Experts available now in Live!

Get 1:1 Help Now