Solved

cobol programming problem

Posted on 2004-04-15
3
403 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
ID: 10839054
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
ID: 10846982
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
ID: 10847775
I understand what is going on now. Thank you all for your help!

Regards,
James
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Non-recursive backtracking, using a stack 1 103
index Out OF Range Exception error 4 54
Beginner to Unreal Engine 4 5 61
Auto-indent certain lines in Notepad++ 10 32
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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 …

867 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

20 Experts available now in Live!

Get 1:1 Help Now