View previous topic :: View next topic
|
Author |
Message |
sancraig16
New User
Joined: 27 Mar 2018 Posts: 26 Location: usa
|
|
|
|
Hi ,
Trying to SORT a file with input as given below
SORT :
SORT FIELDS=(1,2,ZD,A)
Input :
18
6
15
31
27
6
37
38
23
28
35
33
15
26
38
38
37
38
37
Output:
15
15
18
23
26
27
28
31
33
35
37
37
37
38
38
38
38
6
6
The output is incorrect with 2 rows of 6 at the bottom. The trailing spaces is obviously causing the issue for these records . Any way to overcome this? |
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
Try this,
Code: |
INREC OVERLAY=(1:1,2,JFY=(SHIFT=RIGHT))
SORT FIELDS=(1,2,ZD,A) |
You will get leading zeros though in the output |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2010 Location: USA
|
|
|
|
vasanthz wrote: |
You will get leading zeros though in the output |
Not leading ZEROES, but leading BLANKS.
Blanks would cause sorting format ZD to fail; SORT FIELDS=(1,2,CH,A) is more robust. |
|
Back to top |
|
|
sancraig16
New User
Joined: 27 Mar 2018 Posts: 26 Location: usa
|
|
|
|
I did get leading BLANKS and SORT worked. As suggested , I will change the format to CH. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2010 Location: USA
|
|
|
|
sancraig16 wrote: |
I did get leading BLANKS and SORT worked. As suggested , I will change the format to CH. |
If SORT FIELDS=(...,ZD,...) did not fail with some blanks in the field, that means the sort utility code performed extra check on ZD field before handling it in decimal manner. At the level of machine instructions it might fail with decimal ABEND like S0C7.
SORT FIELDS=(...,CH,...) deals in the same manner as ZD, but CH is also irrelevant to not fully correct ZD values.
This is known as more robust code. |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
sancraig16,
You might be able to achieve this without altering the input data by using the UFF format:
UNTESTED:
Code: |
SORT FIELDS=(1,2,UFF,A) |
|
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3048 Location: NYC,USA
|
|
|
|
UFF will work but if you have -ve values also then UFF won't work you will then need SFF. |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
The OPs representative sample does not show any negative symbols in it, so I would leave it to the OP's discretion. |
|
Back to top |
|
|
|