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 

SORT & SPLIT File based on dynamic key value

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Job Control Language(JCL)
View previous topic :: View next topic  
Author Message
viswanathan
Beginner


Joined: 17 Jan 2006
Posts: 26
Topics: 13

PostPosted: Thu Sep 24, 2015 9:46 am    Post subject: SORT & SPLIT File based on dynamic key value Reply with quote

Hi Friends,

Need your help in solving JCL Sort & Split requirement.

--> I have an input file of LRECL = 750.

--> Key field is from position 1 to 8 (Packed decimal)

--> Maximum of 3 key values can occur in a file (values are dynamic)

--> File will be sorted on this key

--> Need to write the records to three different files based on the key values.

Sample Input File:
Code:

20014567 Rec 1
20014567 Rec 1
20014567 Rec 1
20014577 Rec 1
20014577 Rec 1
20014577 Rec 1
20014577 Rec 1
20014587 Rec 1


Output File 1:
Code:

20014567 Rec 1
20014567 Rec 1
20014567 Rec 1

Output File 2:
Code:

20014577 Rec 1
20014577 Rec 1
20014577 Rec 1
20014577 Rec 1

Output File 3:
Code:

20014587 Rec 1
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Sep 24, 2015 10:06 am    Post subject: Reply with quote

viswanathan,

It is quite simple with WHEN=GROUP. You just add a file ID number at the end of the record and validate that field to split into multiple files.

I assumed that your input is unsorted and you need to sort the file and then perform the split. If your input file is already sorted then simply replace the sort fields= statement with OPTION COPY.

Here is a DFSORT JCL which will give you the desired results.

Code:

//STEP0100 EXEC PGM=SORT                                   
//SYSOUT   DD SYSOUT=*                                     
//SORTIN   DD DISP=SHR,DSN=Your Input FB 750 Byte file
//KEY1     DD SYSOUT=*                                     
//KEY2     DD SYSOUT=*                                     
//KEY3     DD SYSOUT=*                                     
//SYSIN    DD *                                             
  SORT FIELDS=(1,8,PD,A)                                   
  OUTREC IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,8),PUSH=(751:ID=1))
  OUTFIL FNAMES=KEY1,BUILD=(1,750),INCLUDE=(751,1,ZD,EQ,1) 
  OUTFIL FNAMES=KEY2,BUILD=(1,750),INCLUDE=(751,1,ZD,EQ,2) 
  OUTFIL FNAMES=KEY3,BUILD=(1,750),SAVE                     
//*

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
viswanathan
Beginner


Joined: 17 Jan 2006
Posts: 26
Topics: 13

PostPosted: Thu Sep 24, 2015 10:43 am    Post subject: Reply with quote

Hi Kolusu,

Thank you so much for the complete JCL. It worked well!

I didn't know that with just one keybegin we could split a file into three ways. A learning for me.

Thanks again!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Job Control Language(JCL) 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