View previous topic :: View next topic
|
Author |
Message |
wiprov
New User
Joined: 13 Feb 2008 Posts: 15 Location: Chennai
|
|
|
|
Hi,
I have an input file as follows...
01 rec1
05 rec1
01 rec2
04 rec1
01 rec3
05 rec2
03 rec1
05 rec3
And i have to to direct this to two o/p files as follows
SORT FIELDS=COPY
OUTFIL FILES=01,INCLUDE=(1,1,CH,EQ,C'01')
OUTFIL FILES=02,INCLUDE=(1,1,CH,EQ,C'05')
But the key part is, i have to pick only first two occurances of either '01' or '05, such that
O/p file -01:
01 rec1
01 rec2
O/p file2:
05 rec1
05 rec2
Is there any direct option in SORT to achieve this? I have already tried creating SEQNUM to the right and filtered based on that (pos,len,LT,3).
Just curious to know, is there any advanced/direct option in SORT to achieve this. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
What does your SyncSort manual say? DFSORT has ACCEPT on OUTFIL which does what you want. Does (your) SyncSort? |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
As there is no ACCEPT parameter in SYNCSORT (v 1.4.1) and as I haven't succeeded in finding an equivalent option, I turned to SYNCTOOL.
There also it was not obvious (as there is no documentation) but I finally nailed it with this:
Code: |
//STEP01 EXEC PGM=SYNCTOOL
//SYSPRINT DD SYSOUT=*
//TOOLMSG DD SYSOUT=*
//SSMSG DD SYSOUT=*
//IN DD *
04 REC1
01 REC1
05 REC1
01 REC2
04 REC2
01 REC3
05 REC2
03 REC1
05 REC3
05 REC4
01 REC4
//TEMP DD DISP=(NEW,PASS),DSN=&TEMP
//OUTP1 DD DISP=SHR,DSN=your.first.output.file
//OUTP2 DD DISP=SHR,DSN=your.second.output.file
//TOOLIN DD *
COPY FROM(IN) TO(TEMP) USING(OUT1)
SUBSET FROM(TEMP) TO(OUTP1) KEEP INPUT FIRST(2)
COPY FROM(IN) TO(TEMP) USING(OUT2)
SUBSET FROM(TEMP) TO(OUTP2) KEEP INPUT FIRST(2)
//OUT1CNTL DD *
INCLUDE COND=(1,2,CH,EQ,C'01')
//OUT2CNTL DD *
INCLUDE COND=(1,2,CH,EQ,C'05') |
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Without ACCEPT, the SEQNUM solution you already have will be the preferred one.
Marso,
SUBSET can take a USING, where you could INCLUDE COND the record-types (individually) that you want. That would cut out a couple of operators. Still going through the file twice... |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
I tried that before:
Code: |
SUBSET FROM(IN) TO(OUTP1) KEEP INPUT FIRST(2) USING(OUT1)
SYT020I SYNCSORT CALLED WITH IDENTIFIER "0001"
SYT063E STOPAFT/SKIPREC/COND CANNOT BE USED WITH "SUBSET" OPERATOR
SYT030I OPERATION COMPLETED WITH RETURN CODE 12 |
I would have been too easy
Maybe it's time to talk to my boss and recommend DFSORT ? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Looking deeper, same thing with DFSORT. I'm just waiting for the SELECT solution, which sorts the file on the record type, and then take the first two dupes (OPTION EQUALS) :-) |
|
Back to top |
|
|
wiprov
New User
Joined: 13 Feb 2008 Posts: 15 Location: Chennai
|
|
|
|
Nice logic. Bunch of thanks for your code. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
wiprov,
Are you saying you are going to use Marso's code (no offence Marso). It reads the entire file twice. You already have a SEQNUM solution. Depending on the size of your file, frequency of running, usual type of stuff, you may be making the wrong choice... |
|
Back to top |
|
|
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
I was just trying and came up with this. Is there something wrong in it?
Code: |
//STEP01 EXEC PGM=SYNCTOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD *
04 REC1
01 REC1
05 REC1
01 REC3
04 REC2
01 REC2
05 REC2
03 REC1
05 REC3
05 REC4
01 REC4
//**
//OUT1 DD SYSOUT=*
//OUT2 DD SYSOUT=*
//**
//TOOLIN DD *
COPY FROM(IN) TO(OUT1) USING(CTL1)
COPY FROM(IN) TO(OUT2) USING(CTL2)
//CTL1CNTL DD *
OPTION STOPAFT=2
INCLUDE COND=(1,2,CH,EQ,C'01')
//CTL2CNTL DD *
OPTION STOPAFT=2
INCLUDE COND=(1,2,CH,EQ,C'05') |
Output
OUT1
Code: |
********
01 REC1
01 REC3
******** |
OUT2
Code: |
*******
05 REC1
05 REC2
******* |
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
mistah kurtz,
No, that's fine. Good shot.
Better than the SEQNUM, which is going to require reading the entire file all the time. This will stop when two records have got past the INCLUDE COND=, so assuming a reasonable distribution of data it will not read anywhere near so many records, despite theoretically reading the entire file twice.
The ACCEPT on OUTFIL would be better, but SyncSort doesn't have that... |
|
Back to top |
|
|
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
Thanks Bill |
|
Back to top |
|
|
JAYACHANDRAN THAMPY
New User
Joined: 06 Jun 2006 Posts: 8
|
|
|
|
Syncsort V1.4.2 supports ACCEPT on OUTFIL |
|
Back to top |
|
|
|