Both the files are of same record length 850 and FB. I need to write the unmatched records in file 2 to a PS. Here we can see the time stamp, two additional records and record count differs.
I have got the unmatched records, but the start and end records are swapped.
Can anyone help me with this sort?
Your JOINKEYS statements do not specify SORTED option. That's why the sort utility performs its internal sort before attempting to join both inputs (FYI: there is no other way to join long files unless they are either sorted, or assumed to be sorted).
When just adding SORTED option you'll get the error "Fx FILE IS NOT SORTED", or similar.
You can try to play with the options "SORTED,NOSEQCK" but the desired output is not guaranteed since the input comes in random order.
Another method:
1) re-number input records from F2 on input (using //CTL2CNTL DD),
2) then SORT by this sequenced field after JOIN (to restore the original order), and
3) finally truncate this field in either OUTREC, or OUTFIL statement.