try with something like
****** ***************************** Top of Data ******************************
000001 //ENRICO1 JOB (ACCT#),'SORT90',NOTIFY=ENRICO,
000002 // CLASS=A,MSGCLASS=X,MSGLEVEL=(1,1)
000003 //* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
000004 //*
000005 //ICE EXEC PGM=SORT
000006 //SYSPRINT DD SYSOUT=*
000007 //SYSOUT DD SYSOUT=*
000008 //SORTIN DD *
000009 D00345 G1245 TEST XXXX
000010 D00345 G1245 MAIN XXXX
000011 D00345 G1245 MAIN XXXX
000012 D00345 G1245 MAIN XXXX
000013 D00345 G1245 MAIN XXXX
000014 D00345 G1245 MAIN XXXX
000015 D00124 G1245 TEST XXXX
000016 D00124 G1245 MAIN XXXX
000017 D00124 G1245 MAIN XXXX
000018 D00124 G1245 MAIN XXXX
000019 D00124 G1245 MAIN XXXX
000020 D00124 G1245 MAIN XXXX
000021 //SORTOUT DD SYSOUT=*
000022 //SYSIN DD *
000023 OPTION COPY
000024 INREC IFTHEN=(WHEN=GROUP,
000025 BEGIN=(14,4,CH,EQ,C'TEST'),
000026 PUSH=(81:SEQ=5))
000027 OUTFIL IFOUTLEN=80,
000028 IFTHEN=(WHEN=(81,5,ZD,EQ,5),
000029 OVERLAY=(1:C'D11111'))
****** **************************** Bottom of Data ****************************
********************************* TOP OF DATA **********************************
D00345 G1245 TEST XXXX
D00345 G1245 MAIN XXXX
D00345 G1245 MAIN XXXX
D00345 G1245 MAIN XXXX
D11111 G1245 MAIN XXXX
D00345 G1245 MAIN XXXX
D00124 G1245 TEST XXXX
D00124 G1245 MAIN XXXX
D00124 G1245 MAIN XXXX
D00124 G1245 MAIN XXXX
D11111 G1245 MAIN XXXX
D00124 G1245 MAIN XXXX
******************************** BOTTOM OF DATA ********************************
tested wilt a LRECL 80 and 'TEST' is in a fixed position
if on the other side 'TEST' may occur anywhere in the record then You could use something like
****** ***************************** Top of Data ******************************
000001 //ENRICO1 JOB (ACCT#),'SORT90',NOTIFY=ENRICO,
000002 // CLASS=A,MSGCLASS=X,MSGLEVEL=(1,1)
000003 //* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
000004 //*
000005 //ICE EXEC PGM=SORT
000006 //SYSPRINT DD SYSOUT=*
000007 //SYSOUT DD SYSOUT=*
000008 //SORTIN DD *
000009 D00345 G1245 TEST XXXX
000010 D00345 G1245 MAIN XXXX
000011 D00345 G1245 MAIN XXXX
000012 D00345 G1245 MAIN XXXX
000013 D00345 G1245 MAIN XXXX
000014 D00345 G1245 MAIN XXXX
000015 D00124 G1245 TEST XXXX
000016 D00124 G1245 MAIN XXXX
000017 D00124 G1245 MAIN XXXX
000018 D00124 G1245 MAIN XXXX
000019 D00124 G1245 MAIN XXXX
000020 D00124 G1245 MAIN XXXX
000021 //SORTOUT DD SYSOUT=*
000022 //SYSIN DD *
000023 OPTION COPY
000024 INREC IFTHEN=(WHEN=GROUP,
000025 BEGIN=(1,80,SS,EQ,C'TEST'),
000026 PUSH=(81:SEQ=5))
000027 OUTFIL IFOUTLEN=80,
000028 IFTHEN=(WHEN=(81,5,ZD,EQ,5),
000029 OVERLAY=(1:C'D11111'))
****** **************************** Bottom of Data ****************************
********************************* TOP OF DATA **********************************
D00345 G1245 TEST XXXX
D00345 G1245 MAIN XXXX
D00345 G1245 MAIN XXXX
D00345 G1245 MAIN XXXX
D11111 G1245 MAIN XXXX
D00345 G1245 MAIN XXXX
D00124 G1245 TEST XXXX
D00124 G1245 MAIN XXXX
D00124 G1245 MAIN XXXX
D00124 G1245 MAIN XXXX
D11111 G1245 MAIN XXXX
D00124 G1245 MAIN XXXX
******************************** BOTTOM OF DATA ********************************