How to Sort with Blanks



IBM's flagship sort product DFSORT for sorting, merging, copying, data manipulation and reporting. Includes ICETOOL and ICEGENER

How to Sort with Blanks

Postby wallacec » Fri Sep 06, 2013 6:06 pm

Hi,

I need to sort a column with characters and blanks in a file. I would like to order the result by ascending order but blanks always come at the top. Could anyone advise how I can still sort in ascending order and have blanks at the bottom?

Below is the example:

Layout:
POS 1-3 KEY
POS 4   FILLER
POS 5-7 STATUS


Input:
1   S10
2   P 
3     


My Result:
3     
2   p
1   S10


Expected Result:
2   p
1   S10
3     


Thank you.
wallacec
 
Posts: 4
Joined: Wed Sep 04, 2013 7:38 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How to Sort with Blanks

Postby prino » Fri Sep 06, 2013 6:31 pm

And how the flipping 'ell are you sorting these fields?

Provide the sort cards!
Robert AH Prins
robert.ah.prins @ the.17+Gb.Google thingy
User avatar
prino
 
Posts: 635
Joined: Wed Mar 11, 2009 12:22 am
Location: Vilnius, Lithuania
Has thanked: 3 times
Been thanked: 28 times

Re: How to Sort with Blanks

Postby wallacec » Fri Sep 06, 2013 7:09 pm

Below is the SORT card:

SORT FIELDS=(005,003,CH,A)       
OUTFIL FNAMES=SORTOUT,           
       OUTREC=(001:001,004,     
               005:005,003)       
wallacec
 
Posts: 4
Joined: Wed Sep 04, 2013 7:38 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How to Sort with Blanks

Postby steve-myers » Fri Sep 06, 2013 8:32 pm

A blank is a character, just like any other character. As such, if a blank can be compared with another character. A summary of the compare order in a character set is its collating sequence. I still recall, for example, back in the days when I rode a train as part of my commute to work. One of my fellow commuters was a gentleman with whom I had occasional professional contact with. From time to time, as it happened, we shared part of our walk from the train station to our respective work locations. I recall one of our conversations on this trek quite clearly. He complained that in EBCDIC numeric characters (e.g,, 0, 1,..., 9) compared higher than any other text character, where in ASCII numeric characters compared lower than most other text characters. In those days I rarely - if ever - had contact with ASCII. My guess is he had had a recent contact with an ASCII user who did not understand very much about the difference in collating sequences, but he did not think it reasonable that the EBCDIC collating sequence should be in this order.

Now at that point in my career I had not given any thought as to the reason the engineers that devised EBCDIC had chosen the codes, and this collating sequence issue did not seem terribly significant to me. In actual fact, it still doesn't, even though I think I understand why numbers are X'Fx', and letters are X'Cx', X'Dx' and X'Ex'.

Regardless, in both EBCDIC and ASCII a blank is lower in the collating sequence than any other character, and that explains the reason why your sorted output is not in the order you appear to expect.
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times

Re: How to Sort with Blanks

Postby Akatsukami » Fri Sep 06, 2013 9:06 pm

Kolusu will be a better guide on this matter than I, but I believe that the collating sequence can be altered with the ALTSEQ statement, and applied to vanilla characters with OPTION CHALT.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times


Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post