control break based on several keys
Posted: Thu Dec 22, 2016 1:59 pm
here a post from another site about mainframe , I have the same requirement but the solution doesn't fit 8 my keys are not contigus )
**********************
We have two key fields key1 and key2. Data is sorted first based on the key1 then based on the key 2.
Now my requirement is like below:
a) Whenever key1 value changed from its previous value seqnum resets to 001
b) For every key1 value if the following key 2 value changes the seqnum increments by one.
c) If it doesn’t changed it keeps the original value
Please see below example
INPUT FILE
Key1 key2
234 112
234 112
234 113
234 114
234 114
234 115
235 112
235 112
235 113
235 113
236 117
237 117
238 117
OUTPUT FILE
Key1 key2 SEQNUM
234 112 001
234 112 001
234 113 002
234 114 003
234 114 003
234 115 004
235 112 001
235 112 001
235 113 002
235 113 002
236 117 001
237 117 001
238 117 001
the solution is working only if keys are contigus
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
234 112
234 112
234 113
234 114
234 114
234 115
235 112
235 112
235 113
235 113
236 117
237 117
238 117
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
INREC IFOUTLEN=80,
IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,7),PUSH=(81:ID=8)),
IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,3),PUSH=(89:81,8)),
IFTHEN=(WHEN=INIT,
OVERLAY=(12:+1,ADD,(81,8,ZD,SUB,89,8,ZD),M11,LENGTH=3))
//*
but when we have something like that
key1 ....... Keys2 .........
how can I have the same result
other question how extend to more than 2 keys
**********************
We have two key fields key1 and key2. Data is sorted first based on the key1 then based on the key 2.
Now my requirement is like below:
a) Whenever key1 value changed from its previous value seqnum resets to 001
b) For every key1 value if the following key 2 value changes the seqnum increments by one.
c) If it doesn’t changed it keeps the original value
Please see below example
INPUT FILE
Key1 key2
234 112
234 112
234 113
234 114
234 114
234 115
235 112
235 112
235 113
235 113
236 117
237 117
238 117
OUTPUT FILE
Key1 key2 SEQNUM
234 112 001
234 112 001
234 113 002
234 114 003
234 114 003
234 115 004
235 112 001
235 112 001
235 113 002
235 113 002
236 117 001
237 117 001
238 117 001
the solution is working only if keys are contigus
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
234 112
234 112
234 113
234 114
234 114
234 115
235 112
235 112
235 113
235 113
236 117
237 117
238 117
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
INREC IFOUTLEN=80,
IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,7),PUSH=(81:ID=8)),
IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,3),PUSH=(89:81,8)),
IFTHEN=(WHEN=INIT,
OVERLAY=(12:+1,ADD,(81,8,ZD,SUB,89,8,ZD),M11,LENGTH=3))
//*
but when we have something like that
key1 ....... Keys2 .........
how can I have the same result
other question how extend to more than 2 keys