Page 1 of 1

combining two input files

PostPosted: Fri Sep 23, 2011 10:58 am
by Manju Venkat
Requirement :
2 input files-File1 (Previous day file), file2(current day file). Need to compare two file if match found should write the file2 record into to the output file. If unmatched, then write the records from file1 and file2 into same output file. Below are the examples mentioned.

example file 1: example file2:
2222   4                                     2222     4                                     
2222   4                                     2222     4
2223   3                                     2222     5 
2223   3                                     2223     3   
2223   3                                     2223     3
2444   7                                     2555     8

output file should be:
2222   4
2222   4
2222   5
2223   3
2223   3
2444   7
2555   8 

Manju.

Re: combining two input files

PostPosted: Fri Sep 23, 2011 10:49 pm
by Frank Yaeger
Manju,

It appears you are comparing record by record (e.g. file1 record1 to file2 record1, file1 record2 to file2 record2, etc). If so, then you can use a DFSORT job like the following to do what you asked for. I assumed your input files have RECFM=FB and LRECL=80, but the job can be changed for other attributes. Also, I assumed when the records match you want the file1 record and then the file2 record which means the expected output you show is a bit off (see below).

//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//IN1 DD *
2222   4
2222   4
2223   3
2223   3
2223   3
2444   7
//IN2 DD *
2222   4
2222   4
2222   5
2223   3
2223   3
2555   8
//SORTOUT DD SYSOUT=*
//SYSIN DD *
  JOINKEYS F1=IN1,FIELDS=(81,8,A),SORTED
  JOINKEYS F2=IN2,FIELDS=(81,8,A),SORTED
  REFORMAT FIELDS=(F1:1,80,F2:1,80)
  OPTION COPY
  OUTFIL IFOUTLEN=80,
         IFTHEN=(WHEN=(1,80,CH,EQ,81,80,CH),BUILD=(81,80)),
         IFTHEN=(WHEN=(1,80,CH,NE,81,80,CH),
          BUILD=(1,80,/,81,80))
/*
//JNF1CNTL DD *
  INREC OVERLAY=(81:SEQNUM,8,ZD)
/*
//JNF2CNTL DD *
  INREC OVERLAY=(81:SEQNUM,8,ZD)
/*


SORTOUT would have:

2222   4
2222   4
2223   3
2222   5
2223   3
2223   3
2444   7
2555   8


Note that the third and fourth records here are from file1 and file2, whereas in your output you show it as file2 and file1 even though you show the reverse for the last two records.