I'm trying to code a DFSORT procedure that would merge 2 files into one with the following model :
<header1>
<detail1>
..
<detail1>
<trailer1>
<header2>
<detail2>
..
etc.
The first input file contains every headers and trailers while the second input file only contains the details records.
The records look like that :
Header : 01XXXXXXCCCCCXXXXXXXXX..
Detail : 02XXXXXXCCCCCXXXXXXXXXXXXXX....
Header : 09XXXXXXCCCCC0000000
The X's are random irrelevant characters
The C's represent the key on which both files are sorted
The counter of the trailer is initialy at 0000000
What I've been able to do so far is just a simple sort merging both files using :
//SORT01 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DISP=SHR,DSN=dsn of input1
// DD DISP=SHR,DSN=dsn of input2
//SORTOUT DD DISP=SHR,DSN=dsn of output
//SYSIN DD *
SORT FIELDS=(9,5,CH,A,1,2,CH,A)
/*
//SYSOUT DD SYSOUT=*
//SORTIN DD DISP=SHR,DSN=dsn of input1
// DD DISP=SHR,DSN=dsn of input2
//SORTOUT DD DISP=SHR,DSN=dsn of output
//SYSIN DD *
SORT FIELDS=(9,5,CH,A,1,2,CH,A)
/*
but I then have to manually count the detail records to change the trailer for each header/details/trailer bloc.
So I need your help to add a counter to each trailer, that would reset back to 0 everytime the sorting key changes
The output file should look like this
01XXXXXX12135XXXXXXXXX
02XXXXXX12135XXXXXXXXXXXXXXXXXXXXXXX
09XXXXXX121350000001
01XXXXXX13135XXXXXXXXX
0200000013135XXXXXXXXXXXXXXXXXXXXXXX
09XXXXXX131350000001
01XXXXXX13335XXXXXXXXX
0200000013335XXXXXXXXXXXXXXXXXXXXXXX
0200000013335XXXXXXXXXXXXXXXXXXXXXXX
09XXXXXX133350000002
etc.
02XXXXXX12135XXXXXXXXXXXXXXXXXXXXXXX
09XXXXXX121350000001
01XXXXXX13135XXXXXXXXX
0200000013135XXXXXXXXXXXXXXXXXXXXXXX
09XXXXXX131350000001
01XXXXXX13335XXXXXXXXX
0200000013335XXXXXXXXXXXXXXXXXXXXXXX
0200000013335XXXXXXXXXXXXXXXXXXXXXXX
09XXXXXX133350000002
etc.
I tried a few things using Frank Yaeger's documentation but nothing succesful so far.
I'm sorry for any english mistake and/or if my post isn't clear enough, but english is not my first langage

Thanks in advance for any help.