View previous topic :: View next topic |
Author |
Message |
flatearther Beginner
Joined: 19 Apr 2007 Posts: 13 Topics: 2 Location: Bethesda, MD
|
Posted: Wed Oct 21, 2009 10:53 pm Post subject: Sorting on Left-justified numeric |
|
|
Quick question - I have a file with a sequence number which is numeric and unfortunately left-justified (with trailing spaces).
Is it possible to sort using this field as the sort key (descending)?
Specifying the field as CH or BI doesn't work, for instance:
Seq No
---------
11
1234
111111
won't sort to
111111
1234
11
because of the left-justification.
Any ideas? |
|
Back to top |
|
|
flatearther Beginner
Joined: 19 Apr 2007 Posts: 13 Topics: 2 Location: Bethesda, MD
|
Posted: Wed Oct 21, 2009 11:07 pm Post subject: |
|
|
Just to clarify - I want to sort on the numerical values of the field (descending) so I want the sort outcome to be:
Seq No
---------
111111
1234
11
but the left justification is messing this up:
Seq No
---------
1234
111111
11 |
|
Back to top |
|
|
Ram Beginner
Joined: 12 Jan 2004 Posts: 53 Topics: 12
|
Posted: Thu Oct 22, 2009 3:11 am Post subject: |
|
|
If you have DFSort installed, use the justify feature.
e.g.
OPTION COPY
OUTREC FIELDS=(1,30,JFY=(SHIFT=RIGHT))
Once its right justified, you can sort it accordingly. |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Thu Oct 22, 2009 10:02 am Post subject: |
|
|
flatearther,
Ram has the right idea but his example shows OUTREC which is executed AFTER sorting.
So use the following DFSORT JCL to get the desired results
Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
11
1234
111111
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(1,6,UFF,D)
INREC OVERLAY=(1,6,JFY=(SHIFT=RIGHT))
//* |
This will the contents of the first 6 bytes as right justified and sort that on descending sequence.
But if you want to retain the left shifted data then add this OUTREC statement
Code: |
OUTREC OVERLAY=(1,6,JFY=(SHIFT=LEFT))
|
This will put the data left justified _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
flatearther Beginner
Joined: 19 Apr 2007 Posts: 13 Topics: 2 Location: Bethesda, MD
|
Posted: Thu Oct 22, 2009 5:30 pm Post subject: |
|
|
That's works great! Thanks a lot for your help. |
|
Back to top |
|
|
Frank Yaeger Sort Forum Moderator
Joined: 02 Dec 2002 Posts: 1618 Topics: 31 Location: San Jose
|
Posted: Fri Oct 23, 2009 10:33 am Post subject: |
|
|
You don't need the INREC or OUTREC statement. Sorting with the UFF format will handle this without any need for JFY. So the DFSORT job would just be:
Code: |
//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
11
1234
111111
/*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(1,6,UFF,D)
/*
|
And SORTOUT would have:
_________________ Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort |
|
Back to top |
|
|
|
|