Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 10326
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 Extend the decimal values in DIVISION Balaryan DFSORT/ICETOOL 3 Thu Oct 05, 2017 4:05 pm
No new posts sort records based on length exceeds ... maxsubrat DFSORT/ICETOOL 7 Wed Oct 04, 2017 4:48 pm
No new posts Addition of two records on 2 fields amar143 SYNCSORT 8 Tue Oct 03, 2017 11:14 am
No new posts JOINKEYS Paired and Unpaired Sort MFwhiz DFSORT/ICETOOL 4 Fri Sep 29, 2017 1:48 am
No new posts Difference in SORT & ICETOOL Mohan Kothakota DFSORT/ICETOOL 5 Fri Sep 22, 2017 4:56 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us