Need to see if I can use my read statements to accomplish 3 types of output?

StackOverflow https://stackoverflow.com/questions/22948849

  •  30-06-2023
  •  | 
  •  

Question

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**
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top