Page 1 of 2

Strange result in SORT Arithmatic Division

Posted: Fri Jun 27, 2008 7:04 pm
by Captain Nero
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.

Posted: Sat Jun 28, 2008 1:19 am
by Frank Yaeger
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.

Posted: Sat Jun 28, 2008 12:01 pm
by Captain Nero
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.

Posted: Sat Jun 28, 2008 8:13 pm
by Frank Yaeger
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.

Posted: Sun Jun 29, 2008 8:43 pm
by Captain Nero
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.

Posted: Mon Jun 30, 2008 10:45 pm
by Frank Yaeger
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).

Posted: Tue Jul 01, 2008 10:38 am
by Captain Nero
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)

Posted: Tue Jul 01, 2008 10:43 am
by Captain Nero
And Thank you so much for the help.

Posted: Tue Jul 01, 2008 7:53 pm
by Frank Yaeger
You're welcome. Glad to hear it was a "user error". Thanks for letting us know. .

DIV - Arithmetic Division in Sort - question

Posted: Sun Mar 30, 2014 6:02 pm
by Anies
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

Posted: Mon Mar 31, 2014 2:59 am
by NicC
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!

Posted: Mon Mar 31, 2014 2:03 pm
by NicC
And, from what I have learned from another forum today:
Rounding is not a problem for SORT, it just rounds down

Posted: Tue Apr 01, 2014 11:23 pm
by DikDude
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.

Posted: Mon Apr 07, 2014 10:05 am
by Anies
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.

Posted: Mon Apr 07, 2014 1:09 pm
by William Collins
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.