Mahesh Kumar
Mahesh Kumar

Reputation: 21

compare two files then matched and umtached records to copy two diff files

I have requirement to compare two files then matched records one file and unmatched into another file using joinkeys in jcl .I'm not sure whether this is the correct one or not. Could you, please, help me? the first input file having the only 18 record length which will compare to input2 first 18 length .if it match then we will wrire record into output file based on the buid condtion and if doesnot match then copy th record into another file

SORT FIELDS=COPY                             
JOINKEYS FILE=F1,FIELDS=(1,18,A)             
JOINKEYS FILE=F2,FIELDS=(1,18,A)             
REFORMAT FIELDS=(F2:1,258,F2:264,1,F2:334,2) 
OUTFIL FNAMES=MATCH                          
SORT FIELDS=COPY                             
JOINKEYS FILE=F1,FIELDS=(1,18,A)             
JOINKEYS FILE=F2,FIELDS=(1,18,A)             
JOIN UNPAIRED,F2,ONLY                        
REFORMAT FIELDS=(F2:1,258,F2:264,1,F2:334,2) 
OUTFIL FNAMES=UNMATCH                        

Upvotes: 0

Views: 12275

Answers (3)

Dhans
Dhans

Reputation: 37

I have tried with the below example. It is working fine. Record length of input and output files are 80. Record format(RECFM) is FB.

//SYSIN    DD    *                                          
  JOINKEYS FILE=F1,FIELDS=(1,10,A),SORTED                   
  JOINKEYS FILE=F2,FIELDS=(1,10,A),SORTED                   
  JOIN UNPAIRED,F1,F2                                       
  REFORMAT FIELDS=(F1:1,10,F2:1,10,?)                       
  OPTION COPY                                               
  OUTFIL FNAMES=F1ONLY,INCLUDE=(21,1,CH,EQ,C'1'),           
  BUILD=(1,10,70X)                                          
  OUTFIL FNAMES=F2ONLY,INCLUDE=(21,1,CH,EQ,C'2'),           
  BUILD=(11,10,70X)                                         
  OUTFIL FNAMES=BOTH,INCLUDE=(21,1,CH,EQ,C'B'),             
  BUILD=(1,10,70X)                                          
/*

Upvotes: 1

Chandra
Chandra

Reputation: 1079

You can implement the logic using 1. JCL program - Use of JOIN KEYS 2. COBOL program - File matching logic (Both the logic are explained in the following link) 3. Easytrieve or REXX program

https://www.youtube.com/watch?v=pQumm7ueYik&list=PLB4QPUJFZRcTsP1cKe2sSIObFMlvkyjnn&index=4

Upvotes: 0

Srinivasan JV
Srinivasan JV

Reputation: 705

Welcome to Stack Overflow! You must use indicator method in dfsort to acheive what you're expecting. See below SORT statements.

JOINKEYS FILE=F1,FIELDS=(1,18,A)             
JOINKEYS FILE=F2,FIELDS=(1,18,A)             
REFORMAT FIELDS=(F2:1,258,F2:264,1,F2:334,2,?) 
OUTFIL FNAMES=BOTH,INCLUDE=(262,1,CH,EQ,C'B'),BUILD=(1,261)                          
OUTFIL FNAMES=F1ONLY,INCLUDE=(262,1,CH,EQ,C'1'),BUILD=(1,258)
OUTFIL FNAMES=F2ONLY,INCLUDE=(262,1,CH,EQ,C'2'),BUILD=(259,3)

The ? in the REFORMAT FIELD is responsible for populating an indicator @ 262nd position. If the key is matched in both the files, 262nd position will have B, means BOTH. If the key is unmatched, 262nd position will let you know, which file the record is from, 1 or 2.

Note:

  • You may change the BUILD statement to write the columns you require, if the keys are unmatched. Ensure you have those columns being mentioned in the REFORMAT FIELDS.

  • Ensure to have the DD names BOTH, F1ONLY and F2ONLY in the JCL.

More details here

Upvotes: 1

Related Questions