MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Split File averagely

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
videlord
Beginner


Joined: 09 Dec 2004
Posts: 147
Topics: 19

PostPosted: Mon Jan 03, 2005 9:46 pm    Post subject: Split File averagely Reply with quote

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)?

Thanks.
Back to top
View user's profile Send private message
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Tue Jan 04, 2005 12:20 am    Post subject: Reply with quote

videlord,

The Sort products (DFSORT / Syncsort) provide a very useful command called SPLIT which writes records in a round-robin fashion to n-output files.

Try this.
Code:

//R010     EXEC PGM=SORT                                     
//SORTIN   DD  *
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
//OUT1     DD  SYSOUT=*
//OUT2     DD  SYSOUT=*
//OUT3     DD  SYSOUT=*
//OUT4     DD  SYSOUT=*
//OUT5     DD  SYSOUT=*
//OUT6     DD  SYSOUT=*
//SYSOUT    DD  SYSOUT=*
//SYSIN      DD  *
  SORT FIELDS=COPY
  OUTFIL FNAMES=(OUT1,OUT2,OUT3,OUT4,OUT5,OUT6),SPLIT
/*


Here is the output:
Code:

OUT1 :
1
7
13

OUT2 :
2
8
14

OUT3 :
3
9
15

OUT4 :
4
10

OUT5 :
5
11

OUT6 :
6
12


This will write record 1 to file 1, rec 2 to file 2, ..... rec 6 to file 6 and again rec 7 to file 1, rec 8 to file 2.....and so on.

Is this okay ? or do u want the first 1/6 * n records to be written to file 1, and next 1/6 * n records to file 2 and so on. Please clarify

Hope this helps,

Thanks,
Phantom
Back to top
View user's profile Send private message
videlord
Beginner


Joined: 09 Dec 2004
Posts: 147
Topics: 19

PostPosted: Tue Jan 04, 2005 1:35 am    Post subject: Reply with quote

Phantom,

Thanks. It's OK.
But how about the other option possible? First 1/6 records to file1, next 1/6 to file2 ...

Charlie
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12359
Topics: 75
Location: San Jose

PostPosted: Tue Jan 04, 2005 1:49 am    Post subject: Reply with quote

videlord,

Please search before posting. Check this topic which discusses a similar issue.

http://www.mvsforums.com/helpboards/viewtopic.php?t=2371&highlight=split

Hope this helps...

Cheers

Kolusu
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Tue Jan 04, 2005 2:26 am    Post subject: Reply with quote

videlord,

Here is crude method to accomplish your requirement.

Code:

//R010    EXEC PGM=SYNCTOOL                       
//TOOLMSG  DD  SYSOUT=*                           
//DFSMSG   DD  SYSOUT=*                           
//INPUT    DD  *                                 
1                                                 
2                                                 
3                                                 
4                                                 
5                                                 
6                                                 
7                                                 
8                                                 
9                                                 
10                                               
11                                               
12                                               
13                                               
14                                               
15                                               
/*                                                   
//OUT1     DD  SYSOUT=*                               
//OUT2     DD  SYSOUT=*                               
//OUT3     DD  SYSOUT=*                               
//OUT4     DD  SYSOUT=*                               
//OUT5     DD  SYSOUT=*                               
//OUT6     DD  SYSOUT=*                               
//TEMP     DD  DSN=&&T1,DISP=(,PASS)                 
//CTL3CNTL DD  DSN=&&T2,DISP=(,PASS)                 
//TOOLIN   DD  *                                     
  COPY FROM(INPUT)  TO(TEMP)  USING(CTL1)             
  COPY FROM(TEMP)             USING(CTL2)             
  COPY FROM(INPUT)            USING(CTL3)             
/*                                                   
//CTL1CNTL DD  *                                     
  OUTFIL TRAILER1=(COUNT),NODETAIL                   
/*                                                   
//CTL2CNTL DD  *                                     
  INREC FIELDS=(2,8,ZD,DIV,+6,EDIT=(TTTTTTTT))       
  OUTREC FIELDS=(1,8,2X,                            * END POS - OUT1 *
                 1,8,ZD,MUL,+2,EDIT=(TTTTTTTT),2X,  * END POS - OUT2 *
                 1,8,ZD,MUL,+3,EDIT=(TTTTTTTT),2X,  * END POS - OUT3 *
                 1,8,ZD,MUL,+4,EDIT=(TTTTTTTT),2X,  * END POS - OUT4 *
                 1,8,ZD,MUL,+5,EDIT=(TTTTTTTT),2X)  * END POS - OUT5 *
  OUTFIL FNAMES=CTL3CNTL,                                             
  OUTREC=(C' OUTFIL FNAMES=OUT1,STARTREC=1,ENDREC=',1,8,80:X,/,       
          C' OUTFIL FNAMES=OUT2,STARTREC=',                           
          1,8,ZD,ADD,+1,EDIT=(TTTTTTTT),C',ENDREC=',11,8,80:X,/,       
          C' OUTFIL FNAMES=OUT3,STARTREC=',                           
         11,8,ZD,ADD,+1,EDIT=(TTTTTTTT),C',ENDREC=',21,8,80:X,/,       
          C' OUTFIL FNAMES=OUT4,STARTREC=',                           
         21,8,ZD,ADD,+1,EDIT=(TTTTTTTT),C',ENDREC=',31,8,80:X,/,       
          C' OUTFIL FNAMES=OUT5,STARTREC=',                           
         31,8,ZD,ADD,+1,EDIT=(TTTTTTTT),C',ENDREC=',41,8,80:X,/,       
          C' OUTFIL FNAMES=OUT6,STARTREC=',                           
         41,8,ZD,ADD,+1,EDIT=(TTTTTTTT),80:X)                         
/*                                                                     


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.

CTL3CNTL:
Code:

OUTFIL FNAMES=OUT1,STARTREC=1,ENDREC=00000002       
OUTFIL FNAMES=OUT2,STARTREC=00000003,ENDREC=00000004
OUTFIL FNAMES=OUT3,STARTREC=00000005,ENDREC=00000006
OUTFIL FNAMES=OUT4,STARTREC=00000007,ENDREC=00000008
OUTFIL FNAMES=OUT5,STARTREC=00000009,ENDREC=00000010
OUTFIL FNAMES=OUT6,STARTREC=00000011                 


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.

Hope this helps,

Thanks,
Phantom
Back to top
View user's profile Send private message
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Tue May 30, 2006 4:58 pm    Post subject: Reply with quote

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:

www.ibm.com/servers/storage/support/software/sort/mvs/peug/
_________________
Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
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


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group