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

Split 1 file into 10 output Files - Syncsort


IBM Mainframe Forums -> SYNCSORT
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Prasanth Kumar

New User


Joined: 22 Apr 2011
Posts: 3
Location: India

PostPosted: Sat Sep 16, 2017 12:02 am
Reply with quote

Hi All,
I am using Syncsort Z/OS 2.1.3 and my requirement is to split 1 input file into 10 output files based on certain conditions:

Input file is a Flat File (FB) of 32127 length can have thousands of records and this count can vary each day. This file has trades and markers and trades and markers.

Total number of o/p files to be written are 10.

On the position 221 and for length 1 if the character is X or Y or Z or P or R or D then write this record to Output File 1 as this is a Trade.

Trades:
INCLUDE=(221,1,CH,EQ,C'X',OR,
221,1,CH,EQ,C'Y',OR,
221,1,CH,EQ,C'Z',OR,
221,1,CH,EQ,C'P',OR,
221,1,CH,EQ,C'R',OR,
221,1,CH,EQ,C'D')

Markers:
INCLUDE=(221,1,CH,EQ,C'7',OR,
221,1,CH,EQ,C'8',OR,
221,1,CH,EQ,C'M',OR,
221,1,CH,EQ,C'C',OR,
221,1,CH,EQ,C'O')

My requirement is i will keep reading the file, writing all the trades to o/p file 1, the moment I hit marker i have to write this another new o/p file 2. Again keep reading and write the trades after the marker to o/p file 3 and so on.

So finally, i should have
File 1 - trades
file 2 - marker
file 3 - trades
file 4 - marker
file 5 - trades
file 6 - marker
.....
file 10 - trades

I need to distribute into 10 files with no duplicates. trades before marker goes to a file, marker goes to another file, again the next set of trades goes to another file and then the next marker goes to another file and so on.

Please help, thank you.

Thanks,
Prasad.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2010
Location: USA

PostPosted: Sat Sep 16, 2017 1:15 am
Reply with quote

I always suggest first of all:
1) RTFM,
2) run simplified test to understand the idea(s) of required operations,
3) update the successful test to the original task



It takes no more than 1 hour as first-time-job, and no more than 10 minutes for others:
Code:
//MARKERS  EXEC PGM=SYNCSORT
//SYSOUT   DD  SYSOUT=*     
//*                         
//SORTIN   DD  *             
X-----TRADES1------         
Y-----TRADES1------         
Z-----TRADES1------         
P-----TRADES1------         
R-----TRADES1------         
D-----TRADES1------         
7-----MARKERS2-----         
8-----MARKERS2-----         
M-----MARKERS2-----         
C-----MARKERS2-----         
O-----MARKERS2-----         
X-----TRADES3------         
Y-----TRADES3------         
Z-----TRADES3------         
P-----TRADES3------         
R-----TRADES3------         
D-----TRADES3------     
7-----MARKERS4-----     
8-----MARKERS4-----     
M-----MARKERS4-----     
C-----MARKERS4-----     
O-----MARKERS4-----     
X-----TRADES5------     
Y-----TRADES5------     
Z-----TRADES5------     
P-----TRADES5------     
R-----TRADES5------     
D-----TRADES5------     
7-----MARKERS6-----     
8-----MARKERS6-----     
M-----MARKERS6-----     
C-----MARKERS6-----     
O-----MARKERS6-----     
X-----TRADES7------     
Y-----TRADES7------     
Z-----TRADES7------     
P-----TRADES7------ 
R-----TRADES7------ 
D-----TRADES7------ 
7-----MARKERS8----- 
8-----MARKERS8----- 
M-----MARKERS8----- 
C-----MARKERS8----- 
O-----MARKERS8----- 
X-----TRADES9------ 
Y-----TRADES9------ 
Z-----TRADES9------ 
P-----TRADES9------ 
R-----TRADES9------ 
D-----TRADES9------ 
7-----MARKERS10---- 
8-----MARKERS10---- 
M-----MARKERS10---- 
C-----MARKERS10---- 
O-----MARKERS10---- 
//*                 
//SORTOUT  DD  SYSOUT=*     DEBUGGING ONLY     
//*                                           
//TRADES1  DD  SYSOUT=*                       
//MARKER2  DD  SYSOUT=*                       
//TRADES3  DD  SYSOUT=*                       
//MARKER4  DD  SYSOUT=*                       
//TRADES5  DD  SYSOUT=*                       
//MARKER6  DD  SYSOUT=*                       
//TRADES7  DD  SYSOUT=*                       
//MARKER8  DD  SYSOUT=*                       
//TRADES9  DD  SYSOUT=*                       
//MARKER10 DD  SYSOUT=*                       
//*                                           
//SYSIN    DD  *                               
 INREC IFTHEN=(WHEN=(1,1,SS,EQ,C'XYZPRD'),     
               BUILD=(1,80,C'T')),             
       IFTHEN=(WHEN=(1,1,SS,EQ,C'78MCO'),     
               BUILD=(1,80,C'M'))             
*                                             
 SORT FIELDS=COPY                             
 OUTREC IFTHEN=(WHEN=GROUP,                                       
                KEYBEGIN=(81,1),                                   
                PUSH=(82:ID=2))                                   
*                                                                 
 OUTFIL FNAMES=TRADES1,INCLUDE=(81,3,CH,EQ,C'T01'),BUILD=(1,80)   
 OUTFIL FNAMES=MARKER2,INCLUDE=(81,3,CH,EQ,C'M02'),BUILD=(1,80)   
 OUTFIL FNAMES=TRADES3,INCLUDE=(81,3,CH,EQ,C'T03'),BUILD=(1,80)   
 OUTFIL FNAMES=MARKER4,INCLUDE=(81,3,CH,EQ,C'M04'),BUILD=(1,80)   
 OUTFIL FNAMES=TRADES5,INCLUDE=(81,3,CH,EQ,C'T05'),BUILD=(1,80)   
 OUTFIL FNAMES=MARKER6,INCLUDE=(81,3,CH,EQ,C'M06'),BUILD=(1,80)   
 OUTFIL FNAMES=TRADES7,INCLUDE=(81,3,CH,EQ,C'T07'),BUILD=(1,80)   
 OUTFIL FNAMES=MARKER8,INCLUDE=(81,3,CH,EQ,C'M08'),BUILD=(1,80)   
 OUTFIL FNAMES=TRADES9,INCLUDE=(81,3,CH,EQ,C'T09'),BUILD=(1,80)   
 OUTFIL FNAMES=MARKER10,INCLUDE=(81,3,CH,EQ,C'M10'),BUILD=(1,80)   
*                                                                 
 END                                                               
//*


I hope, the rest of your job should be clear, isn't it?
Back to top
View user's profile Send private message
magesh23586

Active User


Joined: 06 Jul 2009
Posts: 213
Location: Chennai

PostPosted: Sun Sep 17, 2017 10:03 am
Reply with quote

sergeyken,

OP specified the LRECL=32127 and also condition is @ offset 221,1

Prasanth Kumar wrote:

Input file is a Flat File (FB) of 32127 length can have thousands of records and this count can vary each day. This file has trades and markers and trades and markers.

Total number of o/p files to be written are 10.

On the position 221 and for length 1 if the character is X or Y or Z or P or R or D then write this record to Output File 1 as this is a Trade.


sergeyken wrote:

Code:

 INREC IFTHEN=(WHEN=(1,1,SS,EQ,C'XYZPRD'),     
               BUILD=(1,80,C'T')),             
       IFTHEN=(WHEN=(1,1,SS,EQ,C'78MCO'),     
               BUILD=(1,80,C'M'))



BUILD is unnecessary here and waste of resources, we can use OVERLAY instead

UNTESTED code

Code:

//*                 
//SORTOUT  DD  SYSOUT=*     DEBUGGING ONLY     
//*                                           
//TRADES1  DD  SYSOUT=*                       
//MARKER2  DD  SYSOUT=*                       
//TRADES3  DD  SYSOUT=*                       
//MARKER4  DD  SYSOUT=*                       
//TRADES5  DD  SYSOUT=*                       
//MARKER6  DD  SYSOUT=*                       
//TRADES7  DD  SYSOUT=*                       
//MARKER8  DD  SYSOUT=*                       
//TRADES9  DD  SYSOUT=*                       
//MARKER10 DD  SYSOUT=*
//REST     DD  SYSOUT=*                       
//*                                           
//SYSIN    DD  *
  OPTION COPY
  INREC IFTHEN=(WHEN=(221,1,SS,EQ,C'X,Y,Z,P,R,D'),     
                OVERLAY=(32128:C'T')),             
        IFTHEN=(WHEN=(221,1,SS,EQ,C'7,8,M,C,O'),     
                OVERLAY=(32128:C'M')) 
 
  OUTREC IFTHEN=(WHEN=GROUP,                                       
                KEYBEGIN=(32128,1),                                   
                PUSH=(32129:ID=2))

  OUTFIL FNAMES=TRADES1,INCLUDE=(32128,3,CH,EQ,C'T01'),BUILD=(1,32127)   
  OUTFIL FNAMES=MARKER2,INCLUDE=(32128,3,CH,EQ,C'M02'),BUILD=(1,32127)   
  OUTFIL FNAMES=TRADES3,INCLUDE=(32128,3,CH,EQ,C'T03'),BUILD=(1,32127)   
  OUTFIL FNAMES=MARKER4,INCLUDE=(32128,3,CH,EQ,C'M04'),BUILD=(1,32127)   
  OUTFIL FNAMES=TRADES5,INCLUDE=(32128,3,CH,EQ,C'T05'),BUILD=(1,32127)   
  OUTFIL FNAMES=MARKER6,INCLUDE=(32128,3,CH,EQ,C'M06'),BUILD=(1,32127)   
  OUTFIL FNAMES=TRADES7,INCLUDE=(32128,3,CH,EQ,C'T07'),BUILD=(1,32127)   
  OUTFIL FNAMES=MARKER8,INCLUDE=(32128,3,CH,EQ,C'M08'),BUILD=(1,32127)   
  OUTFIL FNAMES=TRADES9,INCLUDE=(32128,3,CH,EQ,C'T09'),BUILD=(1,32127)   
  OUTFIL FNAMES=MARKER10,INCLUDE=(32128,3,CH,EQ,C'M10'),BUILD=(1,32127)
  OUTFIL FNAMES=REST,SAVE 


Corrected as requested
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2010
Location: USA

PostPosted: Mon Sep 18, 2017 6:25 pm
Reply with quote

magesh23586 wrote:
BUILD is unnecessary here and waste of resources, we can use OVERLAY instead

Waste of resources with BUILD???!!!
OMG, what you are talking about...
magesh23586 wrote:

UNTESTED code

Code:

  INREC IFTHEN=(WHEN=(221,1,SS,EQ,C'X,Y,Z,P,R,D'),     

Using WHEN=(221,1,SS,EQ,C'X,Y,Z,P,R,D') - is a bad idea in general case. The character "comma" (C',') when appeared by a chance will also mark the new group.
What would be a benefit of replacing the correct value C'XYZPRD' with half-correct one C'X,Y,Z,P,R,D'?

In general, I would call all the suggested last updates as "nit-picking"
Back to top
View user's profile Send private message
magesh23586

Active User


Joined: 06 Jul 2009
Posts: 213
Location: Chennai

PostPosted: Mon Sep 18, 2017 9:50 pm
Reply with quote

sergeyken wrote:

Waste of resources with BUILD???!!!
OMG, what you are talking about...


Build - you are rebuilding the entire record again.

Overlay - just overlay the record @ last position.

Building an entire record again is a waste of resources.

The OVERLAY parameter enables you to change particular columns and add fields to the end of a record without rebuilding the entire record. When using the OVERLAY parameter you only need to specify the columns you want to change. The rest of the input record remains unchanged.


sergeyken wrote:

Using WHEN=(221,1,SS,EQ,C'X,Y,Z,P,R,D') - is a bad idea in general case. The character "comma" (C',') when appeared by a chance will also mark the new group.
What would be a benefit of replacing the correct value C'XYZPRD' with half-correct one C'X,Y,Z,P,R,D'?


If ",' is there in the input, it should be avoided, it is just for clarity.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2010
Location: USA

PostPosted: Tue Sep 19, 2017 1:10 am
Reply with quote

magesh23586 wrote:
Building an entire record again is a waste of resources.

If ",' is there in the input, it should be avoided, it is just for clarity.


The record (physically) is re-built exactly in the same manner, either with BUILD, or with OVERLAY. I implemented similar operations in Assembler myself; the difference in syntax doesn't matter.
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 -> SYNCSORT

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Write line by line from two files DFSORT/ICETOOL 7
No new posts Access to non cataloged VSAM file JCL & VSAM 18
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
Search our Forums:

Back to Top