Page 1 of 1

How to Sort with Blanks

PostPosted: Fri Sep 06, 2013 6:06 pm
by wallacec
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.

Re: How to Sort with Blanks

PostPosted: Fri Sep 06, 2013 6:31 pm
by prino
And how the flipping 'ell are you sorting these fields?

Provide the sort cards!

Re: How to Sort with Blanks

PostPosted: Fri Sep 06, 2013 7:09 pm
by wallacec
Below is the SORT card:

SORT FIELDS=(005,003,CH,A)       
OUTFIL FNAMES=SORTOUT,           
       OUTREC=(001:001,004,     
               005:005,003)       

Re: How to Sort with Blanks

PostPosted: Fri Sep 06, 2013 8:32 pm
by steve-myers
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.

Re: How to Sort with Blanks

PostPosted: Fri Sep 06, 2013 9:06 pm
by Akatsukami
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.