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

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


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Jun 24, 2011 12:22 pm
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
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 Developer


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

PostPosted: Fri Jun 24, 2011 10:31 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 3
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 INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Compare only first records of the fil... SYNCSORT 7
Search our Forums:

Back to Top