Sort in specified order other than ascending or descending?



IBM's flagship sort product DFSORT for sorting, merging, copying, data manipulation and reporting. Includes ICETOOL and ICEGENER

Sort in specified order other than ascending or descending?

Postby BryPri55 » Wed Oct 10, 2012 4:01 am

Is there a way to use DSORT to sort based on specified values of a field, rather than in ascending or descending order? Say I had a file with records
02Smith
02Johnson
05Davis
06Thompson
02Jones
03Jackson
05Williams
07Newman

and I needed the records with 05 and 06 in the first two bytes to be in the file before all other records. How could I accomplish that?
BryPri55
 
Posts: 3
Joined: Wed Oct 10, 2012 3:50 am
Has thanked: 0 time
Been thanked: 0 time

Re: Sort in specified order other than ascending or descending?

 

Re: Sort in specified order other than ascending or descendi

Postby BillyBoyo » Wed Oct 10, 2012 5:41 am

Yes, you can. Extend your record by another sort key of one byte. Use IFTHEN to set that to 3 for 05's and 06's otherwise 7. Sort on the one-byte then the two-byte. Should give you what you want.

Where you extend the record depends on whether F or V.

I've used 3 and 7 so there is "space" for other future rearrangement :-) Doesn't have to be a numeric value. If you are unclear, please let us know. If you are clear, please post the solution as it may help others with similar requirements.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Sort in specified order other than ascending or descendi

Postby BryPri55 » Wed Oct 10, 2012 7:16 am

Thank you! I definitely understand what you are telling me I need to do. I don't have a lot of experience using DSORT with anything other than very elementary sorts and selects, however, so I'm not sure what the syntax would look like for extending a file by a byte using IFTHEN. The file I am using is fixed block. If you have time to post a simple example of extending a record by a byte with an IFTHEN statement, that would be appreciated. In the meantime I will look for examples in this forum and online.
BryPri55
 
Posts: 3
Joined: Wed Oct 10, 2012 3:50 am
Has thanked: 0 time
Been thanked: 0 time

Re: Sort in specified order other than ascending or descendi

Postby dick scherrer » Wed Oct 10, 2012 8:08 am

Hello and welcome to the forum,

This previous topic is similar to what you are looking for:
dfsort-icetool-icegener/topic6889.html#p30562

You will be most interested in Frank's solution at the end of the topic.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: Sort in specified order other than ascending or descendi

Postby skolusu » Wed Oct 10, 2012 9:00 pm

BryPri55,

Apart from adding an indicator at the end, you can use ALTSEQ which character EBCDIC, with alternate collating sequence, unsigned. This is similar to format CH, but the characters collate according to the ALTSEQ (alternate collating sequence) table in effect. In your case we are dealing with only numbers in first 2 bytes. So we will change the value of 5(X'F5') to A(X'CA') and 6(X'F6') to B(X'CB') and perform the sort. Note that this will only effect the sorting but contents of your records remain the same.

Use the following DFSORT JCL
//STEP0010 EXEC PGM=SORT               
//SYSOUT   DD SYSOUT=*                 
//SORTIN   DD *                       
02SMITH                               
02JOHNSON                             
05DAVIS                               
06THOMPSON                             
02JONES                               
03JACKSON                             
05WILLIAMS                             
07NEWMAN                               
//SORTOUT  DD SYSOUT=*                 
  SORT FIELDS=(1,2,AQ,A),EQUALS       
  ALTSEQ CODE=(F5CA,F6CB)             
//*


will produce
05DAVIS       
05WILLIAMS   
06THOMPSON   
02SMITH       
02JOHNSON     
02JONES       
03JACKSON     
07NEWMAN     
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
skolusu
 
Posts: 586
Joined: Wed Apr 02, 2008 10:38 pm
Has thanked: 0 time
Been thanked: 39 times

Re: Sort in specified order other than ascending or descendi

Postby BryPri55 » Thu Oct 11, 2012 3:53 am

Awesome! I was able to produce the results I needed using both methods. Thanks for the great posts.
BryPri55
 
Posts: 3
Joined: Wed Oct 10, 2012 3:50 am
Has thanked: 0 time
Been thanked: 0 time


Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post