I am trying to use the SEQNUM trick that Frank Yaeger taught us a while ago on this list to put the record count into a trailer record, but this time in a MERGE operation rather than in a SORT operation. It appears that SEQNUM may be restarting at 1 for each SORTINxx input file, but I can find no documentation to confirm or deny this. Or I may have a misunderstanding of the flow of a MERGE operation. I'd appreciate any help you can give to cure my mistakes.
The business case to be solved is this: I have multiple VB input files (all created in the same ascending order by the same key, with duplicates) to be merged into one file, but all input files each have their own separate header and trailer records. The final output file must have exactly one header and one trailer, and the one trailer must have a count of all the data records (not counting the single header or trailer records). I supply one file with a single unique-key record that is a "DUMMY" trailer record to be used to create the one output trailer record. I developed a simple test scenario to show the problem. In the test scnario the merge key is the first three bytes of each record. Key value 000 is a header record and key value 999 is a trailer record. The merged output file (RECFM=VB,LRECL=84) comes out looking like this: 000FILE HDR DATE=032912,FILE=FILE1.NAME 001DATA REC 001 002DATA REC 002 003DATA REC 003 004DATA REC 004 005DATA REC 005 005DATA REC 005 SECOND TIME 006DATA REC 006 007DATA REC 007 008DATA REC 008 009DATA REC 009 999FILE TLR CNT=00000000001,DATE=000000 As can be seen, the trailer count is not correct. It should be 00000000009. Here is the MERGE control card input I used: OMIT COND=(((5,3,CH,EQ,C'000'),AND, OMIT(HEADER RECORD AND (34,5,CH,NE,C'FILE1')),OR, NOT FILE1) OR (5,3,CH,EQ,C'999')) TRAILER RECORD) * ADD SEQNUM BETWEEN RDW AND DATA. INREC IFTHEN=(WHEN=INIT,BUILD=(1,4,5:SEQNUM,11,ZD,16:5)), * USE SEQNUM-2 TO PUT COUNT OF DATA RECORDS INTO * DUMMY TRAILER RECORD (IDENTIFIED BY X'FAFAFA'). IFTHEN=(WHEN=(16,3,CH,EQ,X'FAFAFA'), OVERLAY=(32:4,11,ZD,SUB,+2,M11,LENGTH=11)) MERGE FIELDS=(016,03,CH,A), EQUALS,FILES=4 SORTIN01 TO 04 OUTREC IFTHEN=(WHEN=(016,03,CH,EQ,C'000'), HEADER RECORD BUILD=(1,4,5:16)), IFTHEN=(WHEN=(16,3,CH,EQ,X'FAFAFA'), TRAILER RECORD BUILD=(1,4,5:C'999',8:19)), IFTHEN=(WHEN=NONE, ALL OTHER RECORDS BUILD=(1,4,5:16)) Here are the four input files, all RECFM=VB,LRECL=84, with their data contents: File #1: 000FILE HDR DATE=032912,FILE=FILE1.NAME 001DATA REC 001 005DATA REC 005 007DATA REC 007 999FILE TLR CNT=00000000003,DATE=032912 File #2: 000FILE HDR DATE=032912,FILE=FILE2.NAME 002DATA REC 002 004DATA REC 004 006DATA REC 006 008DATA REC 008 999FILE TLR CNT=00000000004,DATE=032912 File #3: 000FILE HDR DATE=032912,FILE=FILE3.NAME 003DATA REC 003 005DATA REC 005 SECOND TIME 009DATA REC 009 999FILE TLR CNT=00000000003,DATE=032912 File #4: (DUMMY trailer record to be inserted into merged output) ³³³FILE TLR CNT=00000000000,DATE=000000 Note that the first 3 bytes of the only record in file #4 are X'FAFAFA' so that this record has a higher key value than any other record. Any assistance you can provide would be much appreciated. Peter This message and any attachments are intended only for the use of the addressee and may contain information that is privileged and confidential. If the reader of the message is not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any dissemination of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail and delete the message and any attachments from your system. ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: INFO IBM-MAIN