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

Sort to retain the first record


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Thu Oct 01, 2009 6:56 pm
Reply with quote

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
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Thu Oct 01, 2009 7:08 pm
Reply with quote

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 icon_lol.gif
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Thu Oct 01, 2009 7:35 pm
Reply with quote

Great Expat.It worked thanks icon_biggrin.gif

Code:


//SYSIN    DD *                           
  SORT FIELDS=(1,3,CH,A),EQUALS           
  SUM FIELDS=NONE                         
//*                                       

Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Thu Oct 01, 2009 9:57 pm
Reply with quote

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
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Fri Oct 02, 2009 11:30 am
Reply with quote

Thanks Frank I knew this ICETOOL option already but my requirement was particular for someother option than ICETOOL.
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 -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Need to set RC4 through JCL SORT DFSORT/ICETOOL 5
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
No new posts JCL sort card - get first day and las... JCL & VSAM 9
Search our Forums:

Back to Top