Posted: Mon Jan 03, 2005 9:46 pm Post subject: Split File averagely
I want to split a file averagely, for example:
Split a data set to 6 data sets, each with 1/6 records, how to do?
Can it be done with DFSORT withoud extra program coding (such as REXX)?
Basically the code generates a dynamic sort control card CTL3CNTL as shown below. Change the program name from SYNCTOOL to ICETOOL if you are having DFSORT.
There is a small problem in this solution: Here the no. of records is 15 and no. of output files is 6. so 15/6 = 2.5 but when you use DIV operator in SORT all you get is '2' and not 2.5. So, 2 records are written to the first 5 output files and the remaining 5 records are written to the last file (out 6). So, the last file gets more records most of the time. This could be resolved by verifying the result of Division but that might require more coding.
Joined: 02 Dec 2002 Posts: 1618 Topics: 31 Location: San Jose
Posted: Tue May 30, 2006 4:58 pm Post subject:
Here's a new solution for this requirement that uses the SPLIT1R function of DFSORT available with z/OS DFSORT PTF UK90007 and DFSORT R14 PTF UK90006. Whereas SPLITBY can rotate back to the first data set, resulting in non-contiguous records, SPLIT1R only does one rotation so the records are always contiguous.
Here's a DFSORT job that uses SPLIT1R dynamically to divide any number of input records among any number of output files:
Code:
//S1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN=... input file
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(TRK,(1,1)),DISP=(,PASS)
//C1 DD DSN=&&C1,UNIT=SYSDA,SPACE=(TRK,(1,1)),DISP=(,PASS)
//CTL3CNTL DD *
OUTFIL FNAMES=(OUT01,OUT02,...,OUTnn), <--- change for nn
// DD DSN=*.C1,VOL=REF=*.C1,DISP=(OLD,PASS)
//OUT01 DD DSN=... output file01
//OUT02 DD DSN=... output file02
...
//OUTnn DD DSN=... output filenn <--- change for nn
//TOOLIN DD *
* Get the record count.
COPY FROM(IN) USING(CTL1)
* Generate:
* SPLIT1R=x where x = count/nn.
* nn is the number of output files.
COPY FROM(T1) TO(C1) USING(CTL2)
* Use SPLIT1R=x to split records contiguously among
* the nn output files.
COPY FROM(IN) USING(CTL3)
/*
//CTL1CNTL DD *
OUTFIL FNAMES=T1,REMOVECC,NODETAIL,
TRAILER1=(COUNT=(M11,LENGTH=8))
/*
//CTL2CNTL DD *
OUTREC BUILD=(2X,C'SPLIT1R=',
1,8,ZD,DIV,+nn, <--- set to nn
TO=ZD,LENGTH=8,80:X)
/*
For complete information on SPLIT1R and the other new DFSORT/ICETOOL functions available with the April, 2006 PTFs, see:
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum