Strange result in SORT Arithmatic Division

In this Mainframe Forum - You can post your queries on DFSORT, ICETOOL , SyncSort & JCL Utilities

Moderators: Frank Yaeger, Moderator Group

Captain Nero
Member
Posts: 10
Joined: Fri Jun 20, 2008 4:21 pm
Location: Kolkata, India

Strange result in SORT Arithmatic Division

Post by Captain Nero » Fri Jun 27, 2008 7:04 pm

Hi all,

I have a file in which the 17th and 18th positions have two numeric fields, I want to divide the first one by the second one and populate the 43rd position with a particular edit.

The card I have used in the OUTREC for this is -

OUTREC OVERLAY=(1,33,34:C'|RATIO = ',
43:(17,6,ZD,MUL,+10000000000),DIV,28,6,ZD,
EDIT=(IIIT.TTTTT),53:C'|')
SORT FIELDS=(1,2,CH,A)

However, I am getting some strange values in the 43rd column like sown.
AK - 000001|F - 000000|M - 000001|RATIO = 0.00000|
AL - 000029|F - 000014|M - 000015|RATIO = 3571.42857|
AR - 000013|F - 000005|M - 000008|RATIO = 1700.68027|
AZ - 000032|F - 000012|M - 000020|RATIO = 1581.02766|
CA - 000242|F - 000100|M - 000142|RATIO = 975.60975|
CO - 000028|F - 000012|M - 000016|RATIO = 1403.50877|
CT - 000070|F - 000030|M - 000040|RATIO = 833.33333|

Can somebody please explain me why is this coming and what can be the remedy. I have multiplied the first field by 10000000000 as this was a requirement.
Regards,
Captain N.

User avatar
Frank Yaeger
Moderator
Posts: 812
Joined: Sat Feb 18, 2006 5:45 am
Location: San Jose, CA
Contact:

Post by Frank Yaeger » Sat Jun 28, 2008 1:19 am

I don't know how you got

3571.42857

from 14 and 15 with that statement. When I do it with DFSORT, I get:

3333.33333

which is what I'd expect. Here's why:

DFSORT does integer arithmetic (it throws away the decimal places), so:

(14 * 10000000000)/15 = 9333333333

There are 10 digits in that result but your edit mask of IIIT.TTTTT only has 9 digits, so the digits are mapped right to left and the first digit (the 9 gets dropped). The result is:

3333.33333

If you had 10 digits in your edit mask as IIIIT.TTTTT, the leading digit wouldn't be dropped and you'd get:

93333.3333

But I don't know where you got

3571.42857

You'd have to prove to me that DFSORT produced that result with the input you showed.

By the way, since you're using OVERLAY, you don't need 1,33 - OVERLAY will leave that data as is.
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort

Captain Nero
Member
Posts: 10
Joined: Fri Jun 20, 2008 4:21 pm
Location: Kolkata, India

Post by Captain Nero » Sat Jun 28, 2008 12:01 pm

Hi Frank,

I have put the result directly from the mainframe. However, i will get you the DFSMSG on Monday. I am really quite perplexed to see the results.

Hope something will turn out.
Regards,
Captain N.

User avatar
Frank Yaeger
Moderator
Posts: 812
Joined: Sat Feb 18, 2006 5:45 am
Location: San Jose, CA
Contact:

Post by Frank Yaeger » Sat Jun 28, 2008 8:13 pm

Well, at the very least you should make the edit mask larger so you can see the full result rather than a truncated result.

It would be helpful to "display" the relevant input fields and the actual output values you received for those input fields with and without truncation, all in the same line, as well as the DFSORT messages.
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort

Captain Nero
Member
Posts: 10
Joined: Fri Jun 20, 2008 4:21 pm
Location: Kolkata, India

Post by Captain Nero » Sun Jun 29, 2008 8:43 pm

Yes frank I will make the changes on the mask and the Overlay of the first 33 bytes as you have suggested, however, the input file and the output are right in front of you... My input was without the last column and I have added the last column(Ratio) in the output.

Thanks.
Regards,
Captain N.

User avatar
Frank Yaeger
Moderator
Posts: 812
Joined: Sat Feb 18, 2006 5:45 am
Location: San Jose, CA
Contact:

Post by Frank Yaeger » Mon Jun 30, 2008 10:45 pm

Sanity check. Let's simplify things.

When I run this with DFSORT:

Code: Select all

//S1    EXEC  PGM=ICEMAN                             
//SYSOUT    DD  SYSOUT=*                             
//SORTIN DD *                                        
AK - 000001|F - 000000|M - 000001|                   
AL - 000029|F - 000014|M - 000015|                   
AR - 000013|F - 000005|M - 000008|                   
AZ - 000032|F - 000012|M - 000020|                   
CA - 000242|F - 000100|M - 000142|                   
CO - 000028|F - 000012|M - 000016|                   
CT - 000070|F - 000030|M - 000040|                   
//SORTOUT DD SYSOUT=*                                
//SYSIN    DD    *                                   
  SORT FIELDS=(1,2,CH,A)                             
  OUTREC BUILD=(17,6,ZD,X,28,6,ZD,X,                 
     (17,6,ZD,MUL,+10000000000),DIV,28,6,ZD)         
/*
I get this output:

Code: Select all

     0       1                0    
    14      15       9333333333    
     5       8       6250000000    
    12      20       6000000000    
   100     142       7042253521    
    12      16       7500000000    
    30      40       7500000000    
Please run this job and show what you get along with the //SYSOUT messages. (The output you say you get with the input and control statements you say you use doesn't seem to make any sense, so let's simplify things).
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort

Captain Nero
Member
Posts: 10
Joined: Fri Jun 20, 2008 4:21 pm
Location: Kolkata, India

Post by Captain Nero » Tue Jul 01, 2008 10:38 am

Frank I also got output as expected :) the problem was with an INREC statement which I have put in different control.

Now it is working fine. 8)
Regards,
Captain N.

Captain Nero
Member
Posts: 10
Joined: Fri Jun 20, 2008 4:21 pm
Location: Kolkata, India

Post by Captain Nero » Tue Jul 01, 2008 10:43 am

And Thank you so much for the help.
Regards,
Captain N.

User avatar
Frank Yaeger
Moderator
Posts: 812
Joined: Sat Feb 18, 2006 5:45 am
Location: San Jose, CA
Contact:

Post by Frank Yaeger » Tue Jul 01, 2008 7:53 pm

You're welcome. Glad to hear it was a "user error". Thanks for letting us know. .
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort

Anies
Member
Posts: 2
Joined: Sun Mar 30, 2014 5:57 pm

DIV - Arithmetic Division in Sort - question

Post by Anies » Sun Mar 30, 2014 6:02 pm

Hi Frank, Good morning!
Is it possbile to round the decimal values which comes as the output while using SORT IN / OUTREC - DIV option.

I am new to this portal, if its posted somewhere else please provide me the URL.

Thank you!
Anies

NicC
Active Member
Posts: 650
Joined: Sun Jul 24, 2011 5:27 pm
Location: Down on the pig farm

Post by NicC » Mon Mar 31, 2014 2:59 am

1) You should not address posts to individuals.
2) Frank retired some time ago and no longer participates in the forums
3) Generally, posting URLs of other forums is not encouraged.
4) This topic is 6 years old. You should not reply post to old topics.
5) Your requirement is not to do with the topic of this thread - you should have started a new thread. Maybe a moderator will split it off into its own thread.
6) Welcome to the forum!
Regards
Nic

NicC
Active Member
Posts: 650
Joined: Sun Jul 24, 2011 5:27 pm
Location: Down on the pig farm

Post by NicC » Mon Mar 31, 2014 2:03 pm

And, from what I have learned from another forum today:
Rounding is not a problem for SORT, it just rounds down
Regards
Nic

DikDude
Moderator
Posts: 1001
Joined: Fri Jul 22, 2011 8:39 am
Location: usa

Post by DikDude » Tue Apr 01, 2014 11:23 pm

If you are still having problems, please start a new topic (using th4e Code tag to preserve alignment.

Show a bit of sample input data and the output you want when this particular sample data is run thru your process.

Post the sort control statements and the JCL you use to test.
Have a good one

Anies
Member
Posts: 2
Joined: Sun Mar 30, 2014 5:57 pm

Post by Anies » Mon Apr 07, 2014 10:05 am

I Apologize, i did not get response when i started a new topic.
so writing it up here.
This is my SORT statement

//SYSIN DD *
SORT FIELDS=COPY
OUTFIL FILES=1,
OUTREC=((51,13,ZD,MUL,+10),DIV,40,11,ZD,EDIT=(TT.TT),LENGTH=5)
/*

Input:
51,13 - input - 0000000462018 - PIC 9(12)V9
40,11 - input - 00000030235 - PIC 9(11)

Output:
01.52

Actual Output must be 01.53

I was not able to get the Rounded value.

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Mon Apr 07, 2014 1:09 pm

SORT does not have DWIW.

SORT rounds down. If you want something different, you have to do it yourself. Calculate 10 bigger. Look at the rightmost digit o fhe result, and adjust the digit on the left if necessary.

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others