IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

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: 1752
Location: Tirupur, 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

Senior Member


Joined: 29 Apr 2008
Posts: 2286
Location: USA

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

Senior Member


Joined: 29 Apr 2008
Posts: 2286
Location: USA

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: 2482
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: 3109
Location: NYC,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: 2482
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 All times are GMT + 6 Hours
Forum Index -> SYNCSORT

 


Similar Topics
Topic Forum Replies
No new posts Alternative of JoinKeys in SORT DFSORT/ICETOOL 2
No new posts Sort SMF records? SYNCSORT 6
No new posts To Sort detail records in a file with... SYNCSORT 5
No new posts To Unstring spaces in a field COBOL Programming 3
No new posts Simplify SORT CARD to combine INREC a... DFSORT/ICETOOL 6
Search our Forums:


Back to Top