|
View previous topic :: View next topic
|
| Author |
Message |
hariharan4
New User
Joined: 06 Aug 2008 Posts: 22 Location: chennai
|
|
|
|
Hi,
I've a file with the records like below.
111 xx ....
111 xx ...
111 xx ...
111 yy ....
111 yy ...
222 yy ..
222 yy ...
222 zz ..
333 xx ...
And want the output like below.
111 xx....( as 111 is having max times xx than others)
222 yy .. ( as 222 is having max times yy thn others)
333 xx ...
We want to accomplish this thru DFSORT.
Can anyone suggest how to do this ..
Thanks in Advance,
hari |
|
| Back to top |
|
 |
enrico-sorichetti
Superior Member

Joined: 14 Mar 2007 Posts: 10903 Location: italy
|
|
| Back to top |
|
 |
Escapa
Senior Member

Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
You can use below sortstep....
| Code: |
//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
111 XX ...
111 XX ...
111 XX ...
111 YY ...
111 YY ...
222 YY ...
222 YY ...
222 ZZ ...
333 XX ...
/*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(1,3,CH,A,81,8,ZD,D)
INREC OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,5))
OUTREC OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,3))
OUTFIL BUILD=(1,80),INCLUDE=(81,8,ZD,EQ,1)
/*
|
|
|
| Back to top |
|
 |
hariharan4
New User
Joined: 06 Aug 2008 Posts: 22 Location: chennai
|
|
|
|
Hi,
It is working fine.
Can you please explain the RESTART command used in the above code.
Thanks in Advance,
Hari |
|
| Back to top |
|
 |
guptae
Moderator

Joined: 14 Oct 2005 Posts: 1209 Location: Bangalore,India
|
|
|
|
Hello Hari,
RESTART=(1,5)
It will restart the seq number form 1 depending upon first 5 bytes
means if ur i/p is
11111
11111
22222
22222
33333
so o/p will be
11111 1
11111 2
22222 1
22222 2
33333 1
Hope its clear now |
|
| Back to top |
|
 |
Escapa
Senior Member

Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
| hariharan4 wrote: |
Can you please explain the RESTART command used in the above code.
|
RTFM |
|
| Back to top |
|
 |
hariharan4
New User
Joined: 06 Aug 2008 Posts: 22 Location: chennai
|
|
|
|
//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
111 11 ...
111 11 ...
111 11 ...
111 12 ...
111 12 ...
222 11 ...
222 11 ...
222 12 ...
333 11 ...
/*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(1,3,CH,A,81,8,ZD,D)
INREC OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,6))
OUTREC OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,3))
OUTFIL BUILD=(1,80),INCLUDE=(81,8,ZD,EQ,1)
/*
The output for the above code is
111 12 ... (wrong)
222 12 ...
333 11 ...
The expected Output should be as below
111 11 ... (correct)
222 12 ...
333 11 ...
Thanks in advance
Hari |
|
| Back to top |
|
 |
guptae
Moderator

Joined: 14 Oct 2005 Posts: 1209 Location: Bangalore,India
|
|
|
|
Hello Hari,
Above sort card providing correct output
| Code: |
111 11
222 11
333 11 |
Are you sure that 222 12 instead of 222 11 ... ? |
|
| Back to top |
|
 |
hariharan4
New User
Joined: 06 Aug 2008 Posts: 22 Location: chennai
|
|
|
|
Hi,
very sorry to bother you again and again!!!
we can understand the RESTART command given in INREC.
But what is the purpose of RESTART = (1,3) in the OUTREC? what it exactly does in the above code? It is only bit confusing for us.
Yes ur correct. The expected output should be:
111 11 ...
222 11 ...
333 11 ...
Thanks In Advance,
Hari |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
Hari,
Unless I have misunderstood the requirement isn't it just getting the FIRST record based on the first 3 bytes as key?
IF so SELECT operator with FIRST parm should give the desired results
| Code: |
//STEP0100 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD *
111 XX ...
111 XX ...
111 XX ...
111 YY ...
111 YY ...
222 YY ...
222 YY ...
222 ZZ ...
333 XX ...
//OUT DD SYSOUT=*
//TOOLIN DD *
SELECT FROM(IN) TO(OUT) ON(1,3,CH) FIRST
//* |
|
|
| Back to top |
|
 |
hariharan4
New User
Joined: 06 Aug 2008 Posts: 22 Location: chennai
|
|
|
|
Hi Kolusu,
I think you mistook the requirement. It is not just getting the FIRST record based on the first 3 bytes as key.
Actually we are almost done with the output but we couldn't understand the part of the code
OUTREC OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,3))
That too especially RESTART command in the above code.
Thanks in Advance,
Hari |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
hariharan4,
Hmm so you want to get the max repeated key but you just need 1 key in the output?
If that is the case then you can use the following JCL
| Code: |
//STEP0100 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD *
111 XX ...
111 XX ...
111 XX ...
111 YY ...
111 YY ...
111 YY ...
111 YY ...
222 YY ...
222 YY ...
222 ZZ ...
333 XX ...
//OUT DD SYSOUT=*
//TOOLIN DD *
SELECT FROM(IN) TO(OUT) ON(1,3,CH) FIRST USING(CTL1)
//CTL1CNTL DD *
INREC OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,6))
SORT FIELDS=(1,3,CH,A,81,8,ZD,D)
OUTFIL FNAMES=OUT,BUILD=(1,80)
//* |
|
|
| Back to top |
|
 |
sguhan
New User
Joined: 15 Mar 2010 Posts: 9 Location: Chennai
|
|
|
|
//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
111 XX ...
111 XX ...
111 XX ...
111 YY ...
111 YY ...
222 YY ...
222 YY ...
222 ZZ ...
333 XX ...
/*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(1,3,CH,A,81,8,ZD,D)
INREC OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,5))
OUTREC OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,3))
OUTFIL BUILD=(1,80),INCLUDE=(81,8,ZD,EQ,1)
/*
Could someone please explain how this code logically obtains the record which occurs maximum number of times for a particular key? |
|
| Back to top |
|
 |
Escapa
Senior Member

Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
Ekta has already explained part of this.
You can ask something specific, you did not get in it. |
|
| Back to top |
|
 |
hariharan4
New User
Joined: 06 Aug 2008 Posts: 22 Location: chennai
|
|
|
|
Hi,
The above ICETOOL and SORT code is not working fine for the below input:
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
1111111111111XXXX1 04/24/2009 ARUN
1111111111111XXXX1 04/24/2009 ARUN
1111111111111XXXX1 04/24/2009 ARUN
1111111111111XXXX1 04/25/2009 ARUN
1111111111111XXXX1 04/25/2009 ARUN
1111111111111XXXX1 04/25/2009 ARUN
1111111111111XXXX1 04/24/2010 ARUN
1111111111111XXXX1 04/24/2010 ARUN
1111111111111XXXX1 04/24/2010 ARUN
1111111111111XXXX1 04/23/2010 RAGU
2222222222222XXXX2 04/01/2010 RAJU
2222222222222XXXX2 04/01/2010 RAJU
2222222222222XXXX2 04/05/2010 RAJU
2222222222222XXXX3 04/01/2010 PRAV
2222222222222XXXX2 04/01/2010 RAJU
2222222222222XXXX3 04/01/2010 PRAV
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(1,18,CH,A,81,8,ZD,D)
INREC OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,29))
OUTREC OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,18))
OUTFIL BUILD=(1,88),INCLUDE=(81,8,ZD,EQ,1)
/*
The output is :
1111111111111XXXX1 04/24/2009
2222222222222XXXX2 04/01/2010
2222222222222XXXX3 04/01/2010
The expected output should be as follows:
1111111111111XXXX1 04/24/2009
1111111111111XXXX1 04/25/2009(since this also occurs the maximum)
1111111111111XXXX1 04/24/2010(since this also occurs the maximum)
2222222222222XXXX2 04/01/2010
2222222222222XXXX3 04/01/2010
Thanks in Advance,
Hari |
|
| Back to top |
|
 |
Escapa
Senior Member

Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
Yes you are right, It will give first record in case of matching max count.
Do you want all of the records in that case? |
|
| Back to top |
|
 |
hariharan4
New User
Joined: 06 Aug 2008 Posts: 22 Location: chennai
|
|
|
|
Hi,
Yes we need all the matching maximum records for the given input. In the below input for the given key 1111111111111XXXX1 the maximum occurrance records are 04/24/2009 , 04/25/2009 and 04/24/2010. similarly for the other keys also. Hope your clear with the requirement now.
1111111111111XXXX1 04/24/2009 ARUN
1111111111111XXXX1 04/24/2009 ARUN
1111111111111XXXX1 04/24/2009 ARUN
1111111111111XXXX1 04/25/2009 ARUN
1111111111111XXXX1 04/25/2009 ARUN
1111111111111XXXX1 04/25/2009 ARUN
1111111111111XXXX1 04/24/2010 ARUN
1111111111111XXXX1 04/24/2010 ARUN
1111111111111XXXX1 04/24/2010 ARUN
1111111111111XXXX1 04/23/2010 RAGU
2222222222222XXXX2 04/01/2010 RAJU
2222222222222XXXX2 04/01/2010 RAJU
2222222222222XXXX2 04/05/2010 RAJU
2222222222222XXXX3 04/01/2010 PRAV
2222222222222XXXX2 04/01/2010 RAJU
2222222222222XXXX3 04/01/2010 PRAV
Thanks in Advance,
Hari |
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
| Is your input data already sorted on the first 2 fields? |
|
| Back to top |
|
 |
hariharan4
New User
Joined: 06 Aug 2008 Posts: 22 Location: chennai
|
|
|
|
| Yes |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
hariharan4,
Use the following DFSORT JCL which will give you the desired results
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
1111111111111XXXX1 04/24/2009 ARUN
1111111111111XXXX1 04/24/2009 ARUN
1111111111111XXXX1 04/24/2009 ARUN
1111111111111XXXX1 04/25/2009 ARUN
1111111111111XXXX1 04/25/2009 ARUN
1111111111111XXXX1 04/25/2009 ARUN
1111111111111XXXX1 04/24/2010 ARUN
1111111111111XXXX1 04/24/2010 ARUN
1111111111111XXXX1 04/24/2010 ARUN
1111111111111XXXX1 04/23/2010 RAGU
2222222222222XXXX2 04/01/2010 RAJU
2222222222222XXXX2 04/01/2010 RAJU
2222222222222XXXX2 04/05/2010 RAJU
2222222222222XXXX3 04/01/2010 PRAV
2222222222222XXXX2 04/01/2010 RAJU
2222222222222XXXX3 04/01/2010 PRAV
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(1,18,CH,A,89,8,CH,A,81,8,CH,D),EQUALS
INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,30))),
IFTHEN=(WHEN=GROUP,BEGIN=(81,8,ZD,EQ,1),PUSH=(89:ID=8))
OUTREC IFTHEN=(WHEN=INIT,
OVERLAY=(89:SEQNUM,8,ZD,RESTART=(1,18),
97:SEQNUM,8,ZD,RESTART=(1,30))),
IFTHEN=(WHEN=GROUP,BEGIN=(89,8,ZD,EQ,1),PUSH=(105:81,8),HIT=NEXT),
IFTHEN=(WHEN=GROUP,BEGIN=(97,8,ZD,EQ,1),PUSH=(81:81,8))
OUTFIL INCLUDE=(105,8,CH,EQ,81,8,CH),BUILD=(1,80)
//* |
|
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|