Joined: 24 Nov 2006 Posts: 2 Location: South Africa
Hi,
I need to spilt a file into 3 files and to include the header and trailer records from the input file in all the output files. The output file header record will be exactly the same as the input file header record but the input file trailer record has a count which excludes the header & trailer records. The output file trailer record should have the exact count as the number of detail records in that file i.o.w. if the output file has 202 records, the count in the trailer record should be 200 as the count excludes the header and trailer records.
I have used the following jcl to split the file:
//*
//**--------------------------------------------------------------**
//** Splits the DMRHAK2 file into 3 equal size files viz: **
//** DMRHAAK1, DMRHAAK2 & DMRHAAK3. **
//** Note: This step will run only if there are records in the **
//** DMRHAK2 file. **
//**--------------------------------------------------------------**
//*
//SPLITK2 EXEC PGM=ICETOOL,COND=(0,NE,REPRO1RC)
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//SORTIN DD DSN=QNGG00.DXPACK.DMRHAK2.D0.SQ356,DISP=SHR
//CNT DD DSN=&&C,UNIT=SYSDA,SPACE=(TRK,(1,1)),DISP=(,PASS)
//SPLCTL DD DSN=&&S,UNIT=SYSDA,SPACE=(TRK,(1,1)),DISP=(,PASS)
//OUT1 DD DSN=QNGG00.DXPACK.DMRHAA1.D0.SQ356,DISP=OLD
//OUT2 DD DSN=QNGG00.DXPACK.DMRHAA2.D0.SQ356,DISP=OLD
//OUT3 DD DSN=QNGG00.DXPACK.DMRHAA3.D0.SQ356,DISP=OLD
//TOOLIN DD *
*
*-----------------------------------------*
* GET COUNT OF RECORDS IN INPUT FILE *
*-----------------------------------------*
*
COPY FROM(SORTIN) USING(CTL1)
*
*-----------------------------------------*
* SET UP CONTROL STATEMENT WITH: *
* SPLIT BY=N *
* WHERE N = (COUNT+2)/3 *
*-----------------------------------------*
*
COPY FROM(CNT) TO(SPLCTL) USING(CTL2)
*
*-----------------------------------------*
* SORT WITH: *
* OUTFIL FNAMES=(OUT1,OUT2,OUT3) *
* SPLITBY=N *
*-----------------------------------------*
*
SORT FROM(SORTIN) USING(CTL3)
/*
//CTL1CNTL DD *
OUTFIL FNAMES=CNT,NODETAIL,REMOVECC,
TRAILER1=(COUNT=(M11,LENGTH=8))
/*
//CTL2CNTL DD *
OUTREC FIELDS=(2X,
C'SPLITBY=',((1,8,ZD,ADD,+2),DIV,+3),M11,LENGTH=8,80:X)
/*
//CTL3CNTL DD *
SORT FIELDS=COPY
OUTFIL FNAMES=(OUT1,OUT2,OUT3),
/*
// DD DSN=*.SPLCTL,VOL=REF=*.SPLCTL,DISP=(OLD,PASS)
The data look something like this:
0020080620 (header record)
0132000000001KFWKVA00000000000
0132000039919KFWKVA00000000000
0132000039954KFWKVA00000000000
0132000039971KFWKVA00000000000
99000000598 (trailer record)
This file has a total of 600 records - the count excludes tha header and trailer records.
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
Divinebeing,
The following DFSORT JCL will give you the desired results. I assumed that your header is identified by '00' in first 2 positions and the trailer by '99' in the first 2 bytes. We get the total no: of all the detail records and divide by 3 to split them evenly. however just so you know that some times one of the file may have an additional records if the division does not result in remainder zero
For ex: if you have 600 detailed records then all 3 files have 202 records (200 detail + 1 header and 1 trailer)
If you have 598 records then out1 and out2 will have 201 records (199 detail + 1 header and 1 trailer)
Out 3 will have 202 records (200(598- 2* 199) records + 1 header + 1 tailer
Joined: 24 Nov 2006 Posts: 2 Location: South Africa
Hi Kolusu,
Thanks for the solution - it has worked. Can you please explain this parameter as I may need to split it into 9 or 10 files.
: OUTREC OVERLAY=(81:81,8,ZD,DIV,+3,M11,LENGTH=8,X,
+1,ADD,81,8,ZD,M11,LENGTH=8,X,
+2,MUL,81,8,ZD,M11,LENGTH=8,X,
+1,ADD,(+2,MUL,(81,8,ZD)),M11,LENGTH=8)
as I may need to split it into 9 or 10 files.
Also please explain the trailer parameter as this will need to be changed.
Thanks for all your help.
Regards
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
divinebeing,
Code:
OUTREC OVERLAY=(81:81,8,ZD,DIV,+3,M11,LENGTH=8,X,
We are dividing the seqnum by 3 ( no: of fines we want to split) and the result is stored as 8 byte field with leading zeros . M11 is an edit mask which puts the result in readable format with leading zeroes.
x denotes a space
Code:
+1,ADD,81,8,ZD,M11,LENGTH=8,X,
We are adding +1 to the result we calculated earlier. This will be used to as the STARTREC field for outfil2
Code:
+2,MUL,81,8,ZD,M11,LENGTH=8,X,
We are multiplying the result we got in step1 to use it as ENDREC on file 2
Code:
+1,ADD,(+2,MUL,(81,8,ZD)),M11,LENGTH=8)
We are adding +1 to the step3 calculated result , so that we can use that as STARTREC parm for the last file. Since we want to copy all the records we dont specify the ENDREC parm on the last file.
The trailer parm is created by taking the trailer record and creating a symbol with its contents and we just use them in the next step when spliting the records
Look at the generated Sysin control cards and you will notice the symbol T1