I wish you would make more of an effort to match your examples to your descriptions and explain the "rules" for your examples.
What is the starting position and length of the key field you want to check for duplicates on? Why do you have the first two records in the output and the last two records in the output, but not the other four records? I don't see any difference between the 4 pairs of records.
Assuming your input records are already in order by the key (as shown in your example) and you want to restart the sequence numbers each time the key in positions 1-11 changes (just a guess on the key positions), you can do it with a DFSORT job like this:
Code: Select all
//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
12345600000ZX
12345600000ZY
12345700000ZX
12345700000ZY
12345800000ZX
12345800000ZY
12345600000ZX
12345600000ZY
/*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC OVERLAY=(18:SEQNUM,4,ZD,RESTART=(1,11),90:X)
/*
SORTOUT would be RECFM=FB/LRECL=90 with these records:
Code: Select all
12345600000ZX 0001
12345600000ZY 0002
12345700000ZX 0001
12345700000ZY 0002
12345800000ZX 0001
12345800000ZY 0002
12345600000ZX 0001
12345600000ZY 0002
If that's not what you want, then you need to do a better job of explaining what you do want.