Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

SORT card to sort records in the order by given values?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
mnnaveen

New User


Joined: 22 Feb 2010
Posts: 1
Location: chennai

PostPosted: Fri Jun 24, 2011 12:04 pm    Post subject: SORT card to sort records in the order by given values?
Reply with quote

The requirement is as given below

BC123
AB123
BC234
AB234
CD123
AB456
CD234

i need to sort the above records in the order of first two characters starting with BC, CD , AB.

The output should be
BC123
BC234
CD123
CD234
AB123
AB234
AB456
Back to top
View user's profile Send private message

enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10277
Location: italy

PostPosted: Fri Jun 24, 2011 12:22 pm    Post subject: Reply to: SORT card to sort records in the order by given va
Reply with quote

You can use a DFSORT job like the following:

Code:

//S1      EXEC PGM=SORT
//SYSOUT    DD SYSOUT=*
//SORTIN    DD *
BC123
AB123
BC234
AB234
CD123
AB456
CD234
//SORTOUT   DD SYSOUT=*
//SYSIN     DD *
  INREC  IFTHEN=(WHEN=(1,2,CH,EQ,C'BC'),OVERLAY=(81:C'001')),
         IFTHEN=(WHEN=(1,2,CH,EQ,C'CD'),OVERLAY=(81:C'002')),
         IFTHEN=(WHEN=(1,2,CH,EQ,C'AB'),OVERLAY=(81:C'003'))
  SORT   FIELDS=(81,3,CH,A,3,3,CH,A)
  OUTFIL BUILD=(1,80)

will give the result according to the rules in the initial post

Code:

BC123
BC234
CD123
CD234
AB123
AB234
AB456


if there are more first two chars combinations add as many ifthen as needed

even if 1 sequence substitute was needed for the simple case asked
I used a 3 digit sequence number to allow for 26 times 26 combinations
( up to the limit of the IFTHENs for this approach )

the snippet assumes a recolrd length of 80, it should be easy to provide for a different record length
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Fri Jun 24, 2011 5:30 pm    Post subject:
Reply with quote

This one is simpler aproach...
Code:

//S1    EXEC  PGM=SORT               
//SORTIN DD *                       
BC123                               
AB123                               
BC234                               
AB234                               
CD123                               
AB456                               
CD234                               
//SORTOUT DD SYSOUT=*               
//SYSOUT    DD  SYSOUT=*             
//SYSIN    DD *                     
  SORT FIELDS=(1,2,AQ,A)             
  ALTSEQ CODE=(C3C2,C2C1,C1C3)       

Output will be..
Code:

BC123
BC234
CD234
CD123
AB123
AB234
AB456
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


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

PostPosted: Fri Jun 24, 2011 10:31 pm    Post subject:
Reply with quote

Quote:
This one is simpler aproach...


That may be true for the particular case shown, but the AQ approach is NOT a good general solution for multi-byte keys. If we just change the data a bit, the approach won't work. For example, if the first two characters had to be sorted in the order BC, CB, BB, I don't think the AQ approach could be used, whereas the IFTHEN approach could. In general, AQ is a good approach for changing the order of a single key byte, but not for changing the order of multiple key bytes.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts BI,TO=ZD Changing Values Tyler Dunbar DFSORT/ICETOOL 4 Tue Jul 25, 2017 12:12 am
No new posts SORT to unpack a feild shr_amar DFSORT/ICETOOL 7 Fri Jul 07, 2017 4:32 am
No new posts How to write Specific Fields from Mul... Padhu SYNCSORT 6 Thu Jul 06, 2017 10:26 am
No new posts Optimize sort inrec parse vishwakotin DFSORT/ICETOOL 6 Mon Jun 26, 2017 11:15 pm
No new posts Reduce CPU Times for Join Sort santoshn SYNCSORT 12 Sat Jun 10, 2017 1:40 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us