MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Sort Utility

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
dssenthil
Beginner


Joined: 21 Jul 2004
Posts: 1
Topics: 1

PostPosted: Wed Jul 21, 2004 9:58 am    Post subject: Sort Utility Reply with quote

Hi,
Is it possible to sort the output record in such a way that the input containing in the following format

1000012 goa
1000012 tanjore
1000012 Trichy
1000013 karur
1000013 pune
1000013 trisur

is converted as

sb1000012 goa
tanjore
Trichy
sb1000013 Karur
Pune
Trisur

is this possible by any of the JCL utilities like SORT etc.

Thanks
Back to top
View user's profile Send private message
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Wed Jul 21, 2004 10:17 am    Post subject: Reply with quote

You can use a DFSORT/ICETOOL job like the one below to do what you asked for. I assumed that your input data set has RECFM=FB and LRECL=80, but the job can be changed appropriately for different attributes.

Code:

//S1    EXEC  PGM=ICETOOL
//TOOLMSG   DD  SYSOUT=*
//DFSMSG    DD  SYSOUT=*
//IN DD *
1000012 goa
1000012 tanjore
1000012 Trichy
1000013 karur
1000013 pune
1000013 trisur
/*
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//T2 DD DSN=&&T2,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//CON DD DSN=*.T1,VOL=REF=*.T1,DISP=(OLD,PASS)
//    DD DSN=*.T2,VOL=REF=*.T2,DISP=(OLD,PASS)
//OUT DD SYSOUT=*
//TOOLIN DD *
* IN->T1: Get first record with each key and reformat it
* as follows with a copy of the key in 81-87:
* |sb|key|data|key|
* IN->T2: Get second and subsequent records with each key
* and reformat them as follows with a copy of the key
* in 81-87:
* |data.......|key|
  SELECT FROM(IN) TO(T1) DISCARD(T2) ON(1,7,CH) FIRST USING(CTL1)
* T1/T2->OUT: Sort on key in 81-87 and then remove it.
  SORT FROM(CON) TO(OUT) USING(CTL2)
/*
//CTL1CNTL DD *
  OUTFIL FNAMES=T1,OUTREC=(C'sb',1,20,81:1,7)
  OUTFIL FNAMES=T2,OUTREC=(9,20,81:1,7)
/*
//CTL2CNTL DD *
  OPTION EQUALS
  SORT FIELDS=(81,7,CH,A)
  OUTREC FIELDS=(1,80)
/*

_________________
Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Mon Dec 20, 2004 7:50 pm    Post subject: Reply with quote

With z/OS DFSORT V1R5 PTF UQ95214 or DFSORT R14 PTF UQ95213 Dec, 2004), you can use DFSORT's IFTHEN and RESTART parameters to do this more easily and efficiently as follows:

Code:

//S2    EXEC  PGM=ICEMAN
//SYSOUT  DD  SYSOUT=*
//SORTIN DD *
1000012 goa
1000012 tanjore
1000012 Trichy
1000013 karur
1000013 pune
1000013 trisur
//SORTOUT DD DSN=...  output file
//SYSIN DD *
  OPTION EQUALS
* Sort on positions 1-7.
  SORT FIELDS=(1,7,CH,A)
* Add a seqnum to the end of each record.  Restart the
* seqnum at 1 each time positions 1-7 changes.
  OUTREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,7))),
* If the seqnum is 1, reformat the record as follows:
* |sb|key|data|
   IFTHEN=(WHEN=(81,8,ZD,EQ,+1),BUILD=(C'sb',1,20,80:X)),
* If the seqnum is not 1, reformat the record as follows:
* |data.......|
   IFTHEN=(WHEN=NONE,BUILD=(9,20))
/*


This DFSORT job only takes one SORT pass whereas the DFSORT/ICETOOL job I showed above takes two SORT passes.

SEQNUM,8,ZD,RESTART=(1,7) restarts the seqnum at 1 each time the RESTART field changes, e.g.

Code:

1000012 goa       ...    00000001
1000012 tanjore          00000002
1000012 Trichy           00000003
1000013 karur            00000001
1000013 pune             00000002
1000013 trisur           00000003


That allows us to use IFTHEN to reformat the 00000001 records differently from the other records in only one pass. Note that with the IFTHEN/RESTART solution, we could use copy instead of sort if the records are already in order by the key.

For complete information on all of the new DFSORT and ICETOOL functions available with these DFSORT PTFs, see:

www.ibm.com/servers/storage/support/software/sort/mvs/pdug/
_________________
Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group