|
View previous topic :: View next topic
|
| Author |
Message |
mnnaveen
New User
Joined: 22 Feb 2010 Posts: 1 Location: chennai
|
|
|
|
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 |
|
 |
enrico-sorichetti
Superior Member

Joined: 14 Mar 2007 Posts: 10903 Location: italy
|
|
|
|
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 |
|
 |
Escapa
Senior Member

Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
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 |
|
 |
Frank Yaeger
DFSORT Developer

Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
| 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 |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|