IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search Log in to check your private messages Log in
 

Sort numeric fields with trailing spaces


IBM Mainframe Forums -> SYNCSORT
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sancraig16

New User


Joined: 27 Mar 2018
Posts: 26
Location: usa

PostPosted: Tue Apr 03, 2018 1:21 am
Reply with quote

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
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1689
Location: Tiruppur, India

PostPosted: Tue Apr 03, 2018 2:17 am
Reply with quote

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
View user's profile Send private message
sergeyken

Active Member


Joined: 29 Apr 2008
Posts: 879
Location: Maryland

PostPosted: Tue Apr 03, 2018 2:58 am
Reply with quote

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
View user's profile Send private message
sancraig16

New User


Joined: 27 Mar 2018
Posts: 26
Location: usa

PostPosted: Tue Apr 03, 2018 3:31 am
Reply with quote

I did get leading BLANKS and SORT worked. As suggested , I will change the format to CH.
Back to top
View user's profile Send private message
sergeyken

Active Member


Joined: 29 Apr 2008
Posts: 879
Location: Maryland

PostPosted: Tue Apr 03, 2018 7:57 am
Reply with quote

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
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Tue Apr 03, 2018 6:38 pm
Reply with quote

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
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2508
Location: NY,USA

PostPosted: Tue Apr 03, 2018 10:12 pm
Reply with quote

UFF will work but if you have -ve values also then UFF won't work you will then need SFF.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Tue Apr 03, 2018 10:51 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> SYNCSORT

 

Search our Forum:

Similar Topics
Topic Forum Replies
No new posts COBOL VS SORT Utility for file format... COBOL Programming 6
No new posts Copying data from prev record using SORT SYNCSORT 19
No new posts how to get total count from numeric d... SYNCSORT 9
No new posts Combining more 4 files with sorted or... DFSORT/ICETOOL 3
No new posts Break a record into fields, each fiel... SYNCSORT 2

Back to Top