Apologies if this has been covered but I searched and could not find this particular flavour of a merge request:
I have two files:
- a large keyed master file
- a second smaller keyed file with values for a field I want to drop into the first file where keys match, if no match is found then I want values in master file left alone.
To say it more in English: I have a keyed file of a thousand records where one of the many fields on each record is birthday. On the second file I have 100 records with more accurate birthday values. I want to drop these 100 updated birthdays into the appropriate records (matching key) on the master. If there is no match on key then I want the data currently there not be overwritten but left alone. So 900 records would be unchanged but the 100 would have updated birthdays.
So if master file looks like this
Code:
KEY1 MALE 20010101
KEY2 FEMALE 20010202
KEY3 MALE 20010303
and other file looked like this:
Code:
KEY2 FEMALE 20019999
then I would want output to look like this:
Code:
KEY1 MALE 20010101
KEY2 FEMALE 20019999
KEY3 MALE 20010303
So master records with no match on the second file are left alone but when there is a match the birthday is overwritten with new value. Those Male and Female entries on the records are not part of the key, they are just examples of other fields on the record being left alone.
If you need more specific help, tell me the RECFM and LRECL of each input file, if the records in each file are already sorted by the key or not, if either or both files can have duplicates within it, and the starting position, length and format of all relevant fields in the input files.
Thanks for your help! I might be able to figure this out myself but am under a bit of a time crunch so I'll pass you on the info:
Each file is RECFM=FB and LRECL=148. Both are already sorted on the key which is the first 20 bytes. No duplicate keys are permitted or exist in either file.
If the keys match (columns 1 thru 20), then I want columns 142 thru 148 from the second file to be placed in the same columns in the first file(overwriting what is there). All other columns to be left as is. And if no match is found on the second file then I want the original record left alone. All columns are char.
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
You can use a DFSORT JOINKEYS job like the following. You say you want columns 142-148, but since your date is actually 8 bytes long, I'm guessing you really want 141-148. If not, adjust accordingly.