IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Split a file in 5 files containing equal number of records


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
mgl

New User


Joined: 12 Dec 2005
Posts: 29
Location: Belgium

PostPosted: Mon Feb 06, 2006 5:18 pm
Reply with quote

Hi,
I have to split a file in 5 files containing equal number of records. I will do it with dfsort but i don't see how.The input file contain variable number of records and i have to keep the input sequence.
Example: input file contain records 1 to 100, output file 1 must contain records 1 to 20, output file2 records 21 to 40,... and outfil 5 records 80 to 100.

Could anybody suggest a way to achieve this work with dfSort ?

Many thanks beforehands,
Michel.
Back to top
View user's profile Send private message
fixdoubts

New User


Joined: 21 Oct 2005
Posts: 54

PostPosted: Mon Feb 06, 2006 5:49 pm
Reply with quote

Hi,

This might help you

Code:

//SPLITBY EXEC PGM=ICEMAN
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=INPUT.FILE,DISP=OLD
//01 DD DSN=FILE01,DISP=MOD
//02 DD DSN=FILE02,DISP=MOD
//03 DD DSN=FILE03,DISP=MOD
//04 DD DSN=FILE04,DISP=MOD
//05 DD DSN=FILE05,DISP=MOD
//SYSIN DD *
  SORT FIELDS=COPY
  OUTFIL FNAMES=(01,02,03,04,05),SPLITBY=20
/*


Will copy 20 record each int0 all the output files, but in case if there are more than 100 records it will continue the writing 101-120 record to FILE01 and so on...

Regards,
Back to top
View user's profile Send private message
mgl

New User


Joined: 12 Dec 2005
Posts: 29
Location: Belgium

PostPosted: Mon Feb 06, 2006 8:00 pm
Reply with quote

Thank you for the answer, but that just the problem. In the example i spoke about 100 records but the next run, it will perhaps contain 200 records and so file 1 have to contain records 1 to 40 and not 1 to 20 + 101 to 120.

Regards,
Michel
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Mon Feb 06, 2006 9:40 pm
Reply with quote

Quote:
input file contain records 1 to 100, output file 1 must contain records 1 to 20, output file2 records 21 to 40,... and outfil 5 records 80 to 100.


Will the input file always contain an even multiple of 5 (e.g. 100, 200) or can it contain extra records (e.g. 102). If it can contain extra records, how do you want the records split among the 5 files when you have 102 records? Must the extra 2 records go to the fifth file or can they go to the first file or what?
Back to top
View user's profile Send private message
mgl

New User


Joined: 12 Dec 2005
Posts: 29
Location: Belgium

PostPosted: Mon Feb 06, 2006 10:11 pm
Reply with quote

Hi Frank,

Thanks for your interest to my problem.
If i don't have a multiple of 5, like in your example, i will have some file with one records more than the others. With your example, i will have 2 files with 101 records, and 3 with 100 records. Wich file contain one record more don't have any importance, but records must be in sequence, example: file 1 with records 1 to 101, file 2 with records 102 to 201, ... file 5 records 402 to 502. My problem is that i don't know the amount of records in advance. I can found it in the output message of a preceding step but i don't see how to divide it by 5 and pass this information to a sort step in the same job.

Regards, Michel
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Mon Feb 06, 2006 11:02 pm
Reply with quote

Here's a DFSORT/ICETOOL job dynamically generates the control statements to split the file. For example, if IN has 102 records, CTL3CNTL will have:

Code:

  OPTION COPY                                           
  OUTFIL FNAMES=OUT1,ENDREC=00000020                   
  OUTFIL FNAMES=OUT2,STARTREC=00000021,ENDREC=00000040 
  OUTFIL FNAMES=OUT3,STARTREC=00000041,ENDREC=00000060 
  OUTFIL FNAMES=OUT4,STARTREC=00000061,ENDREC=00000080 
  OUTFIL FNAMES=OUT5,SAVE                               


OUT1 will have 1-20, OUT2 will have 21-40, OUT3 will have 41-60, OUT4 will have 61-80 and OUT5 will have 81-102. Not quite what you said, but hopefully close enough.

Code:

//S1    EXEC  PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN=...  input file
//CT DD DSN=&&T1,UNIT=SYSDA,SPACE=(TRK,(5,5)),DISP=(,PASS)
//CTL3CNTL DD DSN=&&C1,UNIT=SYSDA,SPACE=(TRK,(5,5)),DISP=(,PASS)
//OUT1 DD DSN=...  output file1
//OUT2 DD DSN=...  output file2
//OUT3 DD DSN=...  output file3
//OUT4 DD DSN=...  output file4
//OUT5 DD DSN=...  output file5
//TOOLIN DD *
 COPY FROM(IN) USING(CTL1)
 COPY FROM(CT) USING(CTL2)
 COPY FROM(IN) USING(CTL3)
/*
//CTL1CNTL DD *
  OUTFIL FNAMES=CT,REMOVECC,NODETAIL,
     TRAILER1=(COUNT=(M11,LENGTH=8))
/*
//CTL2CNTL DD *
  OUTFIL FNAMES=CTL3CNTL,
    IFOUTLEN=80,
    IFTHEN=(WHEN=INIT,OVERLAY=(1,8,ZD,DIV,+5,M11,LENGTH=8)),
    IFTHEN=(WHEN=NONE,
      BUILD=(C' OPTION COPY',/,
        C' OUTFIL FNAMES=OUT1,ENDREC=',1,8,/,
        C' OUTFIL FNAMES=OUT2,STARTREC=',
          1,8,ZD,ADD,+1,M11,LENGTH=8,C',ENDREC=',
          1,8,ZD,MUL,+2,M11,LENGTH=8,/,
        C' OUTFIL FNAMES=OUT3,STARTREC=',
          (1,8,ZD,MUL,+2),ADD,+1,M11,LENGTH=8,C',ENDREC=',
          1,8,ZD,MUL,+3,M11,LENGTH=8,/,
        C' OUTFIL FNAMES=OUT4,STARTREC=',
          (1,8,ZD,MUL,+3),ADD,+1,M11,LENGTH=8,C',ENDREC=',
          1,8,ZD,MUL,+4,M11,LENGTH=8,/,
        C' OUTFIL FNAMES=OUT5,SAVE'))
/*
Back to top
View user's profile Send private message
mgl

New User


Joined: 12 Dec 2005
Posts: 29
Location: Belgium

PostPosted: Tue Feb 07, 2006 2:51 pm
Reply with quote

Many thanks

Your solution solve my problem, it is working fine.

Have a great day,
regards, Michel.
Back to top
View user's profile Send private message
mf_user
Currently Banned

New User


Joined: 05 Jan 2006
Posts: 47

PostPosted: Tue Mar 07, 2006 3:53 pm
Reply with quote

Hi,

Can you please provide the SYNCSORT solution for the same?

Thanks a lot.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Tue Mar 07, 2006 9:18 pm
Reply with quote

Quote:
Can you please provide the SYNCSORT solution for the same?


If by "you", you mean "me": I'm a DFSORT developer. DFSORT and Syncsort are competitive products. I'm happy to answer questions on DFSORT and DFSORT's ICETOOL, but I don't answer questions on Syncsort. However, I can tell you that only DFSORT supports the IFTHEN and OVERLAY functions I used in my solution, so you can't use it with Syncsort.

If by "you", you mean somebody else, ignore this post.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Fri May 12, 2006 11:02 pm
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. SPLIT1R only does one rotation among the files 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:

Use [URL] BBCode for External Links
Back to top
View user's profile Send private message
atchuta konduri

New User


Joined: 25 Oct 2007
Posts: 16
Location: mumbai

PostPosted: Fri Dec 11, 2009 4:13 am
Reply with quote

Hi Frank,

This option is working fine with record format FB but with VB it is giving error. Could you please let me know what changes are required to make VB format work?


Thanks,
Atchuta
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Fri Dec 11, 2009 4:39 am
Reply with quote

Just change CTL1CNTL to:

Code:

//CTL1CNTL DD *                                           
  OUTFIL FNAMES=T1,REMOVECC,NODETAIL,VTOF,BUILD=(8X),     
    TRAILER1=(COUNT=(M11,LENGTH=8))                       
Back to top
View user's profile Send private message
atchuta konduri

New User


Joined: 25 Oct 2007
Posts: 16
Location: mumbai

PostPosted: Fri Dec 11, 2009 5:58 am
Reply with quote

Hi Frank,

It is working perfectly. Thanks for your help. Could you send me a link we can find these different options and their explanations.

Thanks,
Atchuta
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Fri Dec 11, 2009 6:28 am
Reply with quote

Quote:
Could you send me a link we can find these different options and their explanations.


See:

ibmmainframes.com/viewtopic.php?t=1348
Back to top
View user's profile Send private message
atchuta konduri

New User


Joined: 25 Oct 2007
Posts: 16
Location: mumbai

PostPosted: Fri Dec 11, 2009 1:02 pm
Reply with quote

icon_biggrin.gif
Back to top
View user's profile Send private message
atchuta konduri

New User


Joined: 25 Oct 2007
Posts: 16
Location: mumbai

PostPosted: Wed Dec 30, 2009 5:00 am
Reply with quote

Hi Frank,

I am getting one other error. Could you please help me out?

I am splitting a file in to 4 equal files and the input files contains less than 4 records (in case), the current ICETOOL logic is getting abended with

ICE007A F SYNTAX ERROR with all empty file allocations.

Suppose if my input file has 3 records then I want my job to be successful with 3 records distributed to first 3 files and the fourth file as an empty file.

Please let me know is this possible, if yes, how?


Thanks,
Atchuta
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Wed Dec 30, 2009 7:04 am
Reply with quote

I need to see exactly what you're doing and the messages you received.

Please send the complete JES log to me offline (yaeger@us.ibm.com) as an attached .txt file and I'll take a look.
Back to top
View user's profile Send private message
atchuta konduri

New User


Joined: 25 Oct 2007
Posts: 16
Location: mumbai

PostPosted: Wed Dec 30, 2009 7:38 am
Reply with quote

I just sent the JES log to your .ibm id. Please find the mail with subject line: ICETOOL SPLIT LOGIC
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Wed Dec 30, 2009 11:30 pm
Reply with quote

Ok, I see the problem. With less records than files, SPLIT1R=0 is generated. We need to ensure that SPLIT1R=1 is generated in that case.

We can do that by changing CTL2CNTL to handle that case. Here's MY revised DFSORT/ICETOOL job. Revise yours accordingly.

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 IFOUTLEN=80,
   IFTHEN=(WHEN=INIT,BUILD=(1:1,8,ZD,DIV,+nn,  <--- set to nn
      TO=ZD,LENGTH=8)),
   IFTHEN=(WHEN=(1,8,ZD,GT,+0),
     BUILD=(2X,C'SPLIT1R=',1,8)),
   IFTHEN=(WHEN=NONE,
     BUILD=(2X,C'SPLIT1R=1'))
/*
Back to top
View user's profile Send private message
atchuta konduri

New User


Joined: 25 Oct 2007
Posts: 16
Location: mumbai

PostPosted: Thu Dec 31, 2009 12:37 am
Reply with quote

Hi Frank,

I have tested it. Its working as expected. Thanks a lot for your help.


Thanks,
Atchuta
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Thu Dec 31, 2009 5:39 am
Reply with quote

Ok. I will update the Smart DFSORT Tricks paper to incorporate the updated job when I get back from vacation.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 0
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
Search our Forums:

Back to Top