I have two files FILE1(key 1 to 6 bytes 9(6) field, LRECL=150) and FILE2 (key 1 to 4 bytes S9(6) Comp-3, LRECL=230).
Now I want write out all the records from FILE2 only if the key field gets a match from FILE1. Please let me know how I can achieve this.
You can do this using any of the sort products(DFSORT or SYNCSORT) if you have any of them installed and the solution differs based on which one you have.
Can you post the sort product info?. Also do you expect duplicate keys in FILE1(or FILE2)?
If you have Syncsort for z/OS 1.2 or later you can use Syncsort's JOIN functionality to do this. But before doing that you should make sure that the keys are in the same format. The below Syncsort job does what you asked for.