View previous topic :: View next topic
|
Author |
Message |
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Hi,
I have one file where there are duplicates and my requirement is to retain the first occurance of the key value
So I tried to do some research on the same and faced strange problem
Code: |
//STEP010 EXEC PGM=SORT
//*
//SORTIN DD *
AAA 123
AAA 000
AAA 456
AAA 764
BBB 222
BBB AAA
BBB 000
CCC AAA
CCC 000
CCC 333
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//*
//SYSIN DD *
SORT FIELDS=(1,3,CH,A)
//*
|
This gave me result
Code: |
AAA 123
AAA 000
AAA 456
AAA 764
BBB 222
BBB AAA
BBB 000
CCC AAA
CCC 000
CCC 333
|
Adding sum fileds
Code: |
//*
//STEP010 EXEC PGM=SORT
//*
//SORTIN DD *
AAA 123
AAA 000
AAA 456
AAA 764
BBB 222
BBB AAA
BBB 000
CCC AAA
CCC 000
CCC 333
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//*
//SYSIN DD *
SORT FIELDS=(1,3,CH,A)
SUM FIELDS=NONE
//*
|
The output was
Code: |
AAA 123
BBB 222
CCC AAA
|
After rearranging the input
Code: |
//STEP010 EXEC PGM=SORT
//*
//SORTIN DD *
AAA 000
AAA 764
BBB 222
AAA 123
AAA 456
CCC AAA
BBB 000
CCC 000
BBB AAA
CCC 333
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//*
//SYSIN DD *
SORT FIELDS=(1,3,CH,A)
//*
|
Output is
Code: |
AAA 123
AAA 000
AAA 764
AAA 456
BBB 000
BBB 222
BBB AAA
CCC 333
CCC 000
CCC AAA
|
Adding sum fileds
Code: |
//SORTIN DD *
AAA 000
AAA 764
BBB 222
AAA 123
AAA 456
CCC AAA
BBB 000
CCC 000
BBB AAA
CCC 333
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//*
//SYSIN DD *
SORT FIELDS=(1,3,CH,A)
SUM FIELDS=NONE
//*
|
Output is
Code: |
AAA 123
BBB 000
CCC 333
|
Why is it working differently and how would I achieve my requirement without using ICETOOL's SELECT statement ?
Thanks in advance. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Try
Code: |
//SYSIN DD *
SORT FIELDS=(1,3,CH,A),EQUAL
SUM FIELDS=NONE
//*
|
It may be EQUALS, I can not recall for definite. Just another sign of old age |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Great Expat.It worked thanks
Code: |
//SYSIN DD *
SORT FIELDS=(1,3,CH,A),EQUALS
SUM FIELDS=NONE
//*
|
|
|
Back to top |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
Alternatively, you can use this DFSORT/ICETOOL job:
Code: |
//S1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD *
AAA 123
AAA 000
AAA 456
AAA 764
BBB 222
BBB AAA
BBB 000
CCC AAA
CCC 000
CCC 333
//OUT DD SYSOUT=*
//TOOLIN DD *
SELECT FROM(IN) TO(OUT) ON(1,3,CH) FIRST
|
ICETOOL takes care of setting EQUALS on automatically.
If you're not familiar with DFSORT and DFSORT's ICETOOL, I'd suggest reading through "z/OS DFSORT: Getting Started". It's an excellent tutorial, with lots of examples, that will show you how to use DFSORT, DFSORT's ICETOOL and DFSORT Symbols. You can access it online, along with all of the other DFSORT books, from:
www.ibm.com/support/docview.wss?rs=114&uid=isg3T7000080 |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Thanks Frank I knew this ICETOOL option already but my requirement was particular for someother option than ICETOOL. |
|
Back to top |
|
|
|