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

Split files based on characters (not on number of records)


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
vinothsubramanian

New User


Joined: 01 Sep 2006
Posts: 39
Location: Chennai, India

PostPosted: Wed Mar 11, 2009 3:41 pm
Reply with quote

Hi,

Is there a way to split a file into 'n' number of files based on the character contained in that file using syncsort.

For Ex:

I/P file:

1234567 890123 200812
1234567 890123 200812
1234568 901234 200811
1234567 890123 200810
1234567 890123 200810
1234568 901234 200809
1234567 890123 200808
1234567 890123 200808
1234568 901234 200807
1234567 890123 200807
1234567 890123 200806
1234568 901234 200805

I want the output files to be split as shown below based on the third column. All columns are of fixed length.
o/p FILE1:
1234567 890123 200812
1234567 890123 200812

o/p FILE2:
1234568 901234 200811

o/p FILE3:
1234567 890123 200810
1234567 890123 200810

o/p FILE4:
1234568 901234 200809

o/p FILE5:
1234567 890123 200808
1234567 890123 200808

o/p FILE6:
1234568 901234 200807
1234567 890123 200807

o/p FILE7:
1234567 890123 200806

o/p FILE8:
1234568 901234 200805

Regards,
Ram.
Back to top
View user's profile Send private message
krisprems

Active Member


Joined: 27 Nov 2006
Posts: 649
Location: India

PostPosted: Wed Mar 11, 2009 5:14 pm
Reply with quote

vinothsubramanian, check the below example and see if this suffices your requirement.

Code:
//OMIT     EXEC PGM=ICEMAN                             
//SYSOUT   DD SYSOUT=*                                 
//SORTIN   DD *
1234567 890123 200812
1234567 890123 200812
1234568 901234 200811
1234567 890123 200810
1234567 890123 200810
1234568 901234 200809
1234567 890123 200808
1234567 890123 200808
1234568 901234 200807
1234567 890123 200807
1234567 890123 200806
1234568 901234 200805
/*                                                     
//FILE1  DD SYSOUT=*                                 
//FILE2  DD SYSOUT=*                                 
.
.
.
//FILEn  DD SYSOUT=*                                 
//SYSIN    DD *                                         
  OPTION COPY                                           
  OUTFIL FNAMES=FILE1,INCLUDE=(POSITION,LENGTH,CH,EQ,C'200812')
  OUTFIL FNAMES=FILE2,INCLUDE=(POSITION,LENGTH,CH,EQ,C'200811')
...
  OUTFIL FNAMES=FILEn,INCLUDE=(POSITION,LENGTH,CH,EQ,C'200805')

In the place of POSITION,LENGTH mention the starting position and length of the 3 field.
Thanks
Krishna
Back to top
View user's profile Send private message
vinothsubramanian

New User


Joined: 01 Sep 2006
Posts: 39
Location: Chennai, India

PostPosted: Wed Mar 11, 2009 10:19 pm
Reply with quote

Hi Krishna,

Thanks for your reply.

This is one way to achieve it if know the values in the third column.

Is there any other way to achieve it if we don't know the values in the third column. But the number of distinct values in the third column is known say 10. So we need to split the file into 10 files based on the third column without knowing the values in the third column.

Regards,
Ram.
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Thu Mar 12, 2009 11:39 pm
Reply with quote

vinothsubramanian,


I am assuming that your input file is already sorted on your third column. If not change the SORT FIELDS=COPY to SORT FIELDS=(16,6,CH,A). you can easily tag an ID number to the third column using the new WHEN=GROUP function of DFSORT available with z/OS DFSORT V1R5 PTF UK90013 (July, 2008) and use that ID to split the records into different files like this:

If you have more than 10 unq values the leftover file will have all the other records

Code:

//STEP0100 EXEC PGM=SORT   
//SYSOUT   DD SYSOUT=*     
//SORTIN   DD *             
1234567 890123 200812
1234567 890123 200812
1234568 901234 200811
1234567 890123 200810
1234567 890123 200810
1234568 901234 200809
1234567 890123 200808
1234567 890123 200808
1234568 901234 200807
1234567 890123 200807
1234567 890123 200806
1234568 901234 200805
//OUT01    DD SYSOUT=*                                             
//OUT02    DD SYSOUT=*                                             
//OUT03    DD SYSOUT=*                                             
//OUT04    DD SYSOUT=*                                             
//OUT05    DD SYSOUT=*                                             
//OUT06    DD SYSOUT=*                                             
//OUT07    DD SYSOUT=*                                             
//OUT08    DD SYSOUT=*                                             
//OUT09    DD SYSOUT=*                                             
//OUT10    DD SYSOUT=*                                             
//LEFTOVER DD SYSOUT=*                                             
//SYSIN    DD *                                                     
  SORT FIELDS=COPY                                                 
  OUTREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD,RESTART=(16,6))),
  IFTHEN=(WHEN=GROUP,BEGIN=(81,8,ZD,EQ,1),PUSH=(89:ID=8))           
  OUTFIL FNAMES=OUT01,BUILD=(1,80),INCLUDE=(89,8,ZD,EQ,01)         
  OUTFIL FNAMES=OUT02,BUILD=(1,80),INCLUDE=(89,8,ZD,EQ,02)         
  OUTFIL FNAMES=OUT03,BUILD=(1,80),INCLUDE=(89,8,ZD,EQ,03)         
  OUTFIL FNAMES=OUT04,BUILD=(1,80),INCLUDE=(89,8,ZD,EQ,04)         
  OUTFIL FNAMES=OUT05,BUILD=(1,80),INCLUDE=(89,8,ZD,EQ,05)         
  OUTFIL FNAMES=OUT06,BUILD=(1,80),INCLUDE=(89,8,ZD,EQ,06)         
  OUTFIL FNAMES=OUT07,BUILD=(1,80),INCLUDE=(89,8,ZD,EQ,07)         
  OUTFIL FNAMES=OUT08,BUILD=(1,80),INCLUDE=(89,8,ZD,EQ,08)         
  OUTFIL FNAMES=OUT09,BUILD=(1,80),INCLUDE=(89,8,ZD,EQ,09)         
  OUTFIL FNAMES=OUT10,BUILD=(1,80),INCLUDE=(89,8,ZD,EQ,10)         
  OUTFIL FNAMES=LEFTOVER,SAVE                                       
/*                                                                 


If you don't have the July, 2008 PTF installed, ask your System Programmer to install it (it's free).

For complete details on the new WHEN=GROUP and the other new functions available with PTF UK90013, see:

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

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Fri Mar 13, 2009 10:02 am
Reply with quote

vinothsubramanian,

Here's another way of achieving the same without using 'WHEN=GROUP'. As pointed out by Kolusu, your input data seems to be sorted on third field.
If not, you might want to modify the SORT statement.
Code:
//STEP1    EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTIN   DD DSN= Input file --> FB/LRECL=80
//OUT01    DD DSN= Output- 1  --> FB/LRECL=80
//OUT02    DD DSN= Output- 2  --> FB/LRECL=80
//OUT03    DD DSN= Output- 3  --> FB/LRECL=80
//OUT04    DD DSN= Output- 4  --> FB/LRECL=80
//OUT05    DD DSN= Output- 5  --> FB/LRECL=80
//OUT06    DD DSN= Output- 6  --> FB/LRECL=80
//OUT07    DD DSN= Output- 7  --> FB/LRECL=80
//OUT08    DD DSN= Output- 8  --> FB/LRECL=80
//OUT09    DD DSN= Output- 9  --> FB/LRECL=80
//OUT10    DD DSN= Output- 10 --> FB/LRECL=80
//SYSIN    DD *
 INREC IFTHEN=(WHEN=INIT,
       OVERLAY=(81:SEQNUM,8,ZD,89:SEQNUM,8,ZD,RESTART=(16,6))),
       IFTHEN=(WHEN=(89,8,ZD,EQ,1),
       OVERLAY=(97:SEQNUM,8,ZD)),
       IFTHEN=(WHEN=NONE,
       OVERLAY=(105:SEQNUM,8,ZD,97:81,8,ZD,SUB,105,8,ZD,M11,LENGTH=8))
 SORT FIELDS=COPY
 OUTFIL FNAMES=OUT01,INCLUDE=(97,8,ZD,EQ,01),BUILD=(1,80)
 OUTFIL FNAMES=OUT02,INCLUDE=(97,8,ZD,EQ,02),BUILD=(1,80)
 OUTFIL FNAMES=OUT03,INCLUDE=(97,8,ZD,EQ,03),BUILD=(1,80)
 OUTFIL FNAMES=OUT04,INCLUDE=(97,8,ZD,EQ,04),BUILD=(1,80)
 OUTFIL FNAMES=OUT05,INCLUDE=(97,8,ZD,EQ,05),BUILD=(1,80)
 OUTFIL FNAMES=OUT06,INCLUDE=(97,8,ZD,EQ,06),BUILD=(1,80)
 OUTFIL FNAMES=OUT07,INCLUDE=(97,8,ZD,EQ,07),BUILD=(1,80)
 OUTFIL FNAMES=OUT08,INCLUDE=(97,8,ZD,EQ,08),BUILD=(1,80)
 OUTFIL FNAMES=OUT09,INCLUDE=(97,8,ZD,EQ,09),BUILD=(1,80)
 OUTFIL FNAMES=OUT10,INCLUDE=(97,8,ZD,EQ,10),BUILD=(1,80)
Back to top
View user's profile Send private message
vinothsubramanian

New User


Joined: 01 Sep 2006
Posts: 39
Location: Chennai, India

PostPosted: Fri Mar 13, 2009 12:28 pm
Reply with quote

Hi Kolusu,

Thanks for your reply. As pointed by you, the WHEN=GROUP didn't work in our system.

Hi arcvns,

The reply posted by you works exactly the way I wanted. Thanks for the solution. However could you please kindly explain me what does this line exactly does:
105:SEQNUM,8,ZD,97:81,8,ZD,SUB,105,8,ZD,M11,LENGTH=8

Thanks to both of you once again for helping to resolve this request.

Regards,
Ram.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Fri Mar 13, 2009 12:49 pm
Reply with quote

vinothsubramanian,

It's a small sequence number trick by which we assign a unique sequence number to each group.
Code:
105:SEQNUM,8,ZD,97:81,8,ZD,SUB,105,8,ZD,M11,LENGTH=8

The above piece of code overlays a sequence no. at pos-105 which is again subtracted from the sequence number already present at pos-81 and the result is formatted into 8 digit numeric with leading zeros at pos-97.

You have not mentioned your sort product. If you still have any queries on the keywords used, I would suggest going through the product manuals.
In case if you dont have a manual and

If you have SyncSort: Contact SyncSort support or send a PM to Alissa Margulies. I m sure the'll guide you further.
If you have DFSORT: The link to the manual is available in the "IBM Manuals" on the top of this screen.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Fri Mar 13, 2009 12:55 pm
Reply with quote

I just noticed that your initial post says you have SyncSort. Guess Kolusu also missed that part. icon_lol.gif
Back to top
View user's profile Send private message
vinothsubramanian

New User


Joined: 01 Sep 2006
Posts: 39
Location: Chennai, India

PostPosted: Fri Mar 13, 2009 2:40 pm
Reply with quote

Hi arcvns,

So Kind of you.

I understood the logic and thanks for your help.

Regards,
Ram.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Fri Mar 13, 2009 2:50 pm
Reply with quote

You're welcome. icon_smile.gif
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 -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Write line by line from two files DFSORT/ICETOOL 7
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Substring number between 2 characters... DFSORT/ICETOOL 2
Search our Forums:

Back to Top