0

I have been asked to write program to process 2 input files (customer and employee), matching the keys of both files and producing the following 3 output files:

  • File-1: records that are on both files
  • File-2: records that are on the customer file but not the employee file
  • File-3: records that are on the employee file but not the customer file

My loop is set so that it checks one record in customer file against every record in the employee file and then gets another key-pair value from the customer file and starts the process over.

Currently:

  1. Matching Records - Must be in File1 and File2 (This works)
  2. Records that are in File1 but not in File2 (Not working)
  3. Records that are in File2 but not in File1 (Not working)

Questions: Is there a way to use the same read paragraphs as I have currently to accomplish all of my tasks at one time, without having to rerun the JCL for each file compare type

The code that I have posted works for ONLY the matching case

Code: (Record Layout -- This all works)

01  MAIN-LINE1.                                  
    05 FILLER               PIC X(03). <-- won't use in comparison          
    05 ID-1                 PIC X(09).           
    05 FILLER               PIC X(01).           
    05 KEY-1                PIC X(20).           
    05 FILLER               PIC X(47).           

01  MAIN-LINE2.                                  
    05 ID-2                 PIC X(09).           
    05 FILLER               PIC X(55).           
    05 KEY-2                PIC X(20).           
    05 FILLER               PIC X(66).           

Read statements below. This is called from one Perform Match-Infile1... which does work.

This code below works for a Matching situation in the files.

MATCH-INFILE1.                                                   
    READ INFILE1 INTO MAIN-LINE1                                 
       AT END                                                    
          MOVE 'Y' TO EOF1                                       
          GO TO X-INFILE1                                        
       NOT AT END                                                
          PERFORM READ-INFILE2 THRU X-INFILE2 UNTIL EOF2 = 'Y'   
    END-READ.                                                    
X-INFILE1. EXIT.                                                 

READ-INFILE2.                                                    
    READ INFILE2 INTO MAIN-LINE2                                 
      AT END                                                     
         MOVE 'Y' TO EOF2                                        
         GO TO X-INFILE2                                         
      NOT AT END                                                 

         PERFORM COMP-FILE THRU X-COMP-FILE  <-- I did not include this because 
                                                 I forgot to but can add it in in 
                                                 the morning when I have access 
                                                 to the mainframe. (simple compare)                     
    END-READ.                                                    
X-INFILE2. EXIT.

Record Layout

Customer Layout:

**107458982**       ****FM00000000000713432****CH   <-- discard the CH

Employee Layout: (discard the SD two byte fields)

SD  **331067113**  **FFM00000000004556402**
Bruce Martin
  • 10,358
  • 1
  • 27
  • 38
user3491862
  • 384
  • 1
  • 3
  • 13
  • Are you user3376708, or you found a sample of their code, or COBOL is being taught like that these days? – Bill Woodger Apr 08 '14 at 23:09
  • As you can see from Bruce's answer and my understanding, your question is far from clear. You must clarify the description of the required processing. Also please show your code which you believe to be working. With what you have above, `INFILE2` will read till end-of-file with the first record on `INFILE1`. What happens then? I do hope you don't `CLOSE` then `OPEN` the file again. – Bill Woodger Apr 08 '14 at 23:30
  • This is me Rosetta. this is the code that I am using on the main frame. And that do not really teach us we learn as we go. – user3491862 Apr 09 '14 at 01:32
  • @user3491862 I have updated the question based (from your answers) on my understanding of the problem). Can you please review my updates !!! – Bruce Martin Apr 09 '14 at 02:28
  • @user3491862 what should happen if a key occurs multiple times in a file ??? – Bruce Martin Apr 09 '14 at 02:38
  • @user3491862 this site is here to help you but more importantly to help other people with the same issue in the future. For the second part, it is important that the questions are clear; see http://stackoverflow.com/questions/how-to-ask for details. – Bruce Martin Apr 09 '14 at 02:45
  • If the key is a match multiple times in a file then the file should be written over to the new file as well. I do not think that there will be many cases of this because from what I say most keys were unique to their specific file. – user3491862 Apr 09 '14 at 13:01
  • 2
    This is not a job to be writing custom COBOL code for. Consider using your local SORT utility. SyncSort and DFSort are both more than capable of doing what you have outlined above. Almost every mainframe installation will have one or the other of these utilities available. – NealB Apr 09 '14 at 15:58
  • Yes, @NealB, a simple JOINKEYS with three OUTFILs. However, given the name of the files, ( ending in .txt) this may be for a non-Mainframe (where it could be done in an analagous way, without COBOL again, probably). – Bill Woodger Apr 09 '14 at 16:27

1 Answers1

2

I do not think it is possible to do all three tasks with your current code. Also what would happen if the files contained 1,000,000 records. You would be reading a file 1,000,000 times. It would take forever to finish (assuming the hard-disks survived).


For this type of processing I would suggest a sort-merge process:

  • Sort the files into key sequence
  • Do a merge on the 2 files (for 3 files the process is similar, you just have more complicated evaluate).

The processing logic for 2 files in key sequence becomes:

 while not eof
    evaluate true
       when key-file1 < key-file2
         Write file1-record to output-file-2
         read file1
       when key-file1 > key-file2
         Write file2-record to output-file-3
         read file2
       when key-file1 = key-file2
            /* match processing, 
               will involve reading at least one of the files */     
            move key-file1              to hold-key
            while key-file1 =  hold-key
               Write Output-File-1
               read file1
            end
            while key-file2 =  hold-key
               read file2
            end
      end
 end

There will be End-of-file logic to add in

Note: It is unclear from the question how multiple entries for the same key should be handled

Bruce Martin
  • 10,358
  • 1
  • 27
  • 38
  • The output are three distinct files 1. a file with all matching records that are in both the input files -- Employee1.txt and Customer.txt 2. Second file is all the records that are in Employee but not in Customer. 3. The third file are all of the records that are in Customer but not in Employee. – user3491862 Apr 09 '14 at 01:27
  • I have two input files. Customer.txt --- Employee.txt These are the two files that i have two compare. – user3491862 Apr 09 '14 at 01:33
  • 1
    You need to update your question (otherwise it will be closed) and specify the 3 files and the relation ship between them – Bruce Martin Apr 09 '14 at 01:36
  • I have updated the question. There are two input files and 3 output files. – user3491862 Apr 09 '14 at 01:40