View previous topic :: View next topic
|
Author |
Message |
athiqmsr Warnings : 2 New User
Joined: 27 Jul 2006 Posts: 10
|
|
|
|
my problem is I have two input files(with thousands of records), I need to compare both the files and check if the record present in first file is present in second file or not.
Can you suggest me the procedure to do this? |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
There are several threads on the sort forum showing how that can be done with sort. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
athiqmsr wrote: |
all the fields in my first record are not same in the second records, so I have to select only some key fields, I think this can be done only thru' program.
My problem is I have two files, I have to read first record in the first file & compare with the records in the second file, if the record is present I ve to write, If not I ve to read the second record in file1 & continue the process.
Can you give me sample code for this? |
Is there a field or fields in the first file that are the same (not so much position but content) in the second file? You read file1 and read file2 and if afield1 = a field2 and bfield1 = b field2 then write else read file2 again and go back and compare? |
|
Back to top |
|
|
abhijeet3162002
New User
Joined: 05 Jul 2004 Posts: 6 Location: mumbai
|
|
|
|
What kinda files you are using?
If Files are KSDS your job will get simplified.
Read 1st KSDS sequentially and for every read, take a record key of first
file and randomly search for the key in second file.
If you are using ESDS files (or flat files). Read first file sequentially and after every read of first file, read second file till end of records or till you found the matching records.
Let me know if I am not clear...
Cheers |
|
Back to top |
|
|
athiqmsr Warnings : 2 New User
Joined: 27 Jul 2006 Posts: 10
|
|
|
|
Thanks Abhijeet,
I am using sequential files.
I am trying your method, but facing some problem, can you give me sample code for the same. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
athiqmsr wrote: |
all the fields in my first record are not same in the second records, so I have to select only some key fields, I think this can be done only thru' program.
My problem is I have two files, I have to read first record in the first file & compare with the records in the second file, if the record is present I ve to write, If not I ve to read the second record in file1 & continue the process.
Can you give me sample code for this? |
Is there a field or fields in the first file that are the same (not so much position but content) in the second file? You read file1 and read file2 and if afield1 = a field2 and bfield1 = b field2 then write else read file2 again and go back and compare? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Suggest that you get both files in the same sequence - by whatever it is you want to compare (i.e. account-no or ssn or "the whole record", or?).
When you have the files in sequence, you can do what you want with sort (as others have mentioned).
If you look in the dfsort forum, you will find solutons - but they will require the data be "in order".
If one or both files are VSAM but not in the order you need for comparison, i'd suggest getting the data in sequential files and then proceeding. |
|
Back to top |
|
|
|