I've read the manuals about GROUPing with BEGIN and KEYBEGIN and how they can be used together. What I am struggling with is how I can achieve my expected results below.
I know what BEGINs my group, but I can't determine the END of the group, other than change of key.
Input Data:
111 DATA ...... 1
111 HEADING AAA 2
111 DATA ...... 3
111 HEADING BBB 4
111 DATA ...... 5
111 DATA ...... 6
222 DATA ...... 1
222 DATA ...... 2
222 HEADING AAA 3
222 DATA ...... 4
222 DATA ...... 5
222 HEADING BBB 6
222 DATA ...... 7
111 HEADING AAA 2
111 DATA ...... 3
111 HEADING BBB 4
111 DATA ...... 5
111 DATA ...... 6
222 DATA ...... 1
222 DATA ...... 2
222 HEADING AAA 3
222 DATA ...... 4
222 DATA ...... 5
222 HEADING BBB 6
222 DATA ...... 7
Expected Results I want to acheive:
111 DATA ...... 1
111 HEADING AAA 2 111AAA
111 DATA ...... 3 111AAA
111 HEADING BBB 4 111BBB
111 DATA ...... 5 111BBB
111 DATA ...... 6 111BBB
222 DATA ...... 1
222 DATA ...... 2
222 HEADING AAA 3 222AAA
222 DATA ...... 4 222AAA
222 DATA ...... 5 222AAA
222 HEADING BBB 6 222BBB
222 DATA ...... 7 222BBB
111 HEADING AAA 2 111AAA
111 DATA ...... 3 111AAA
111 HEADING BBB 4 111BBB
111 DATA ...... 5 111BBB
111 DATA ...... 6 111BBB
222 DATA ...... 1
222 DATA ...... 2
222 HEADING AAA 3 222AAA
222 DATA ...... 4 222AAA
222 DATA ...... 5 222AAA
222 HEADING BBB 6 222BBB
222 DATA ...... 7 222BBB
Code I've attempted, but is not quite there for what I wanted:
//TESTSORT EXEC ICETOOL
//SYSIN DD *
COPY FROM(SORTIN) TO(SORTOUT) USING(IND1)
/*
//SORTIN DD *
111 DATA ...... 1
111 HEADING AAA 2
111 DATA ...... 3
111 HEADING BBB 4
111 DATA ...... 5
111 DATA ...... 6
222 DATA ...... 1
222 DATA ...... 2
222 HEADING AAA 3
222 DATA ...... 4
222 DATA ...... 5
222 HEADING BBB 6
222 DATA ...... 7
/*
//SORTOUT DD SYSOUT=*
//IND1CNTL DD *
INREC IFTHEN=(WHEN=GROUP,
KEYBEGIN=(001,003),
BEGIN=(005,007,CH,EQ,C'HEADING'),
PUSH=(020:001,003,
013,003))
/*
//*
//SYSIN DD *
COPY FROM(SORTIN) TO(SORTOUT) USING(IND1)
/*
//SORTIN DD *
111 DATA ...... 1
111 HEADING AAA 2
111 DATA ...... 3
111 HEADING BBB 4
111 DATA ...... 5
111 DATA ...... 6
222 DATA ...... 1
222 DATA ...... 2
222 HEADING AAA 3
222 DATA ...... 4
222 DATA ...... 5
222 HEADING BBB 6
222 DATA ...... 7
/*
//SORTOUT DD SYSOUT=*
//IND1CNTL DD *
INREC IFTHEN=(WHEN=GROUP,
KEYBEGIN=(001,003),
BEGIN=(005,007,CH,EQ,C'HEADING'),
PUSH=(020:001,003,
013,003))
/*
//*
with undesired result:
111 DATA ...... 1 111...
111 HEADING AAA 2 111AAA
111 DATA ...... 3 111AAA
111 HEADING BBB 4 111BBB
111 DATA ...... 5 111BBB
111 DATA ...... 6 111BBB
222 DATA ...... 1 222...
222 DATA ...... 2 222...
222 HEADING AAA 3 222AAA
222 DATA ...... 4 222AAA
222 DATA ...... 5 222AAA
222 HEADING BBB 6 222BBB
222 DATA ...... 7 222BBB
111 HEADING AAA 2 111AAA
111 DATA ...... 3 111AAA
111 HEADING BBB 4 111BBB
111 DATA ...... 5 111BBB
111 DATA ...... 6 111BBB
222 DATA ...... 1 222...
222 DATA ...... 2 222...
222 HEADING AAA 3 222AAA
222 DATA ...... 4 222AAA
222 DATA ...... 5 222AAA
222 HEADING BBB 6 222BBB
222 DATA ...... 7 222BBB
Any assistance would be great. Thanks.