Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
Yes, you can't do it exactly like that. The INREC etc would operate after the JOIN and you can't create the file for the join like that.
What you need is JNFnCNTL datasets for additional control cards, one for each dataset:
//JNF1CNTL DD *
//JNF2CNTL DD *
You can then do a GROUP for each file (you specify, in this type of case, your dataset name on each input to the join) and establish an ID which you will match on.
In one JNF1CNTL add (OVERLAY) a number to your "record" when you identify your control record. BUILD just the data you want to add, the ID and the "1" and SUM on the ID. Out of this CNTL you'll get all IDs with data if present and either 0 or 1.
On the other CNTL just output your record with the ID. This CNTL you don't need to let do the SORT, so put SORTED,NOSEQCK (check spelling of last) on the JOINKEYS. Overlay the ID at the end (if fixed records).
Do the join on the IDs.
REFORMAT to include all of the whole file and the data and 0/1 from the other file.
Interrogate the 0/1, update current record, if a 1, use the data, else don't.
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
anatol,
It isn't that complicated. Assuming you ALWAYS have 1 and ONLY CTL record per group , the following DFSORT JCL will give you the desired results. The trick here is to use the same file twice and from the second file pick only the CTL records and attach a seqnum which will be matched with the GROUP ID from file 1. Since we are building the match key , we know it is sorted so you can join the records as if you are copying.