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 

Splitting file on the basis of different keywords

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


Joined: 03 Nov 2021
Posts: 24
Topics: 7

PostPosted: Mon Oct 27, 2025 6:35 am    Post subject: Splitting file on the basis of different keywords Reply with quote

Hi Team,

I have query related to sort card.
We have one input file having different record types as below.

Code:
##header1
##file name
01 abc type 0011
02 dataline1
03 dataline2
10end of file
##header2
##file name
01 abc type 0022
02 dataline1
03 dataline2
10end of file
##header3
##file name
01 abc type 0011
02 dataline1
03 dataline2
10end of file
##header4
##file name
01 abc type 0033
02 dataline1
03 dataline2
10end of file


I want to split the file into 3 different files on the basis of different type(third rec of 4 bytes under each header, rec starting with '01' and field position is 13 i.e. 0011/0022/0033) under the ##Header1/2/3/...

The rec starts from ##Header and ends at 10end of file.

For ex: the output files should look like below:
First file :
Code:

##header1
##file name
01 abc type 0011
02 dataline1
03 dataline2
10end of file
##header3
##file name
01 abc type 0011
02 dataline1
03 dataline2
10end of file


Second file :
Code:

##header2
##file name
01 abc type 0022
02 dataline1
03 dataline2
10end of file


Third File:
Code:

##header3
##file name
01 abc type 0011
02 dataline1
03 dataline2
10end of file


The record seq should be same as input file. Could you please help me out on this. We are not able to achieve it in one step.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Mon Oct 27, 2025 9:12 am    Post subject: Reply with quote

Srishti Rawat,
You have been a member of this site for quite some time and yet you failed to provide the basic information such as the DCB properties of the input file. bonk

Assuming your input has RECFM=FB and LRECL=80 and every group has '01' record, the following untested DFSORT JCL will give you the desired results.
Code:

//STEP0100 EXEC PGM=SORT
//SYSOUT   DD SYSOUT=* 
//INA      DD DISP=SHR,DSN=Your.input.fb.lrecl.80.file
//INB      DD DISP=SHR,DSN=Same.input.fb.lrecl.80.file
//FILE0011 DD SYSOUT=*                                               
//FILE0022 DD SYSOUT=*                                               
//FILE0033 DD SYSOUT=*                                               
//SYSIN    DD *                                                     
  OPTION COPY                                                       
  JOINKEYS F1=INA,FIELDS=(81,08,A),SORTED,NOSEQCK                   
  JOINKEYS F2=INB,FIELDS=(81,08,A),SORTED,NOSEQCK                   
  REFORMAT FIELDS=(F1:01,80,                                   
                   F2:13,04)                                         
                                                                     
  OUTFIL FNAMES=FILE0011,INCLUDE=(81,04,CH,EQ,C'0011'),BUILD=(01,80)
  OUTFIL FNAMES=FILE0022,INCLUDE=(81,04,CH,EQ,C'0022'),BUILD=(01,80)
  OUTFIL FNAMES=FILE0033,INCLUDE=(81,04,CH,EQ,C'0033'),BUILD=(01,80)
/*                                                                   
//JNF1CNTL DD *                                                     
  INREC IFTHEN=(WHEN=GROUP,                                         
               BEGIN=(01,08,CH,EQ,C'##HEADER'),                     
                 END=(01,02,CH,EQ,C'10'),                           
                PUSH=(81:ID=8))                                     
/*                                                                   
//JNF2CNTL DD *                                                     
  INCLUDE COND=(01,02,CH,EQ,C'01')                                   
  INREC OVERLAY=(81:SEQNUM,8,ZD)                                     
/*

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


Joined: 03 Nov 2021
Posts: 24
Topics: 7

PostPosted: Tue Oct 28, 2025 11:57 am    Post subject: Reply with quote

Thanks a lot Kolusu. My bad I forgot to mention the file length. But this was good.

Just that, my input file is a volume file having around 50-60 million recs. So is there any way we can achieve the same solution in one step as above without using join keys.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Wed Oct 29, 2025 1:05 am    Post subject: Reply with quote

Srishti Rawat wrote:
Thanks a lot Kolusu. My bad I forgot to mention the file length. But this was good.


Srishti Rawat

And once again you forgot the DCB properties.

Srishti Rawat wrote:

Just that, my input file is a volume file having around 50-60 million recs. So is there any way we can achieve the same solution in one step as above without using join keys.


Srishti Rawat

huh? One step ? The solution above is indeed one step ? so what exactly is 1 step in your opinion ? Looks like I have some learning to do
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Srishti Rawat
Beginner


Joined: 03 Nov 2021
Posts: 24
Topics: 7

PostPosted: Wed Oct 29, 2025 2:27 am    Post subject: Reply with quote

I meant same as the solution you have given in one step. Similarly can we have without join keys since the input file is too big.

I think my statement was not clear.

And you are a pro Kolusu, I am already so thankful for your help since years. I dont think there is anything you can learn from me or I can tell you which you dont know in DFSORT Smile
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Wed Oct 29, 2025 4:19 am    Post subject: Reply with quote

Srishti Rawat wrote:
I meant same as the solution you have given in one step. Similarly can we have without join keys since the input file is too big.


Srishti Rawat,

You do realize that JNF2 task is ONLY reading 1 record per group and it is a COPY operations for both tasks.

Srishti Rawat wrote:

I think my statement was not clear.


Indeed you keep on insisting on another solution and yet you fail to provide the important information. DCB properties of the input file.

Depending on DCB, you can

1. Push the header record( record # 1) to end of all the records in the group at the end. If the file is VB, then you need to change as you want to retain the variable record.

2. Push the 2nd record after the first record to all records in the group.

3. On OUTFIL omit the first 2 records and then use "/' to build the 2 records from the end that you pushed.

I highly doubt this will as efficient as the JOINKEYS solution.

Srishti Rawat wrote:

And you are a pro Kolusu, I am already so thankful for your help since years. I dont think there is anything you can learn from me or I can tell you which you dont know in DFSORT Smile


There is always room to learn and am willing to learn that will be helpful in the long run.
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Srishti Rawat
Beginner


Joined: 03 Nov 2021
Posts: 24
Topics: 7

PostPosted: Wed Oct 29, 2025 7:41 am    Post subject: Reply with quote

Thanks Kolusu.
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 -> 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