View previous topic :: View next topic
|
Author |
Message |
swathykrishnan
New User
Joined: 01 Oct 2010 Posts: 43 Location: Bangalore
|
|
|
|
Hi
I have 3 variables with the definition given below
A FIXED BIN(15,2)
B FIXED BIN(15,2)
C FIXED BIN(5,2)
And the the following operation will be performed on these variables
A=ROUND((B * (ROUND(PREC(C/100.5,4),3)),2)
This code will give ONCODE 310 when B is having 13 digits in integer part. It will work fine till B is having 12 digits in integer part. We can use MULTIPLY function to avoid this issue. But it will cause truncation of decimal fields. Is there any other way to fix this issue? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
I don't think you have fully described your problem.
If the sub-calculation of C, for instance, returns a value of 1, are you saying you'd get an error with B having 13 digits before the decimal place? |
|
Back to top |
|
|
swathykrishnan
New User
Joined: 01 Oct 2010 Posts: 43 Location: Bangalore
|
|
|
|
Hi Bill
The value of C will be always always <=100. If its sub calculation gives 1 it wont create any issues. Say value of C as 12.55 and B=9874567654321.88 the program will abend with ONCODE 310. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
So, if you, in your data definition, have a maximum of 13 positions before the decimal place, and you have a 13 non-decimal-digit number, and you multiply by 10, you get 14 digits, which don't fit, so POP.
You definition should be made big enough to contain the maximum value that is reasonable for the program to handle. |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1315 Location: Vilnius, Lithuania
|
|
|
|
You do not, EVER, use "fixed bin (15,2)" variables in PL/I.
If you want to use fractions in PL/I you use FIXED DEC!
Given the numbers you post, 9874567654321.88 and 12.55, you also don't have a clue as to what a "fixed bin (15,2)" actually means, as neither of them can ever be stored into a variable of that type and precision. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
you don't do it with cobol either.
lot of knuckleheads think binary computations are faster,
(even though z/os has hardware / middleware / decimal functions)
and all the bytes you can save with binary fields.
a lot of misconceptions and little understanding lead to problems like the ts has posted.
did the rastelle thumb a few years ago. did not know that it was you. |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1787 Location: Bloomington, IL
|
|
|
|
dbzTHEdinosauer wrote: |
lot of knuckleheads think binary computations are faster,
(even though z/os has hardware / middleware / decimal functions)
|
z/OS??? System/360 had microcoded decimal instructions in 1964.
These toy software engineers with experience limited to toy computers need to grow up before they try programming in the real world |
|
Back to top |
|
|
swathykrishnan
New User
Joined: 01 Oct 2010 Posts: 43 Location: Bangalore
|
|
|
|
Hi Prino.
That was a mistake from my side.. I am using FIXED DEC only...
Code: |
A FIXED DEC(15,2)
B FIXED DEC(15,2)
C FIXED DEC(5,2) |
In the example we can see B is having 13 digits integer and 2 digits decimal. And subcalculation of C will have 3 decimal part. So the result of multiplication will have 18 digits. At that time only the program will end with 310.
FLOAT DECIMAL will fix this issue. But ROUND is not working on FLOAT DEC. And if we move it to FIXED DEC it will take 15 digits from left and last 3 digits of decimal part will get truncated. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Presumably PL/I has an equivalent to Cobol's ARITH(31) compiler option, if your problem is a plain lack of digits.
Unrelated, but with A being such a vast number, are you really sure your user is worried about +/- .01 from the final rounding?
It is unusual to me to see the rounding of the intermediate products. If that is what the user wants, OK. |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1315 Location: Vilnius, Lithuania
|
|
|
|
Bill Woodger wrote: |
Presumably PL/I has an equivalent to Cobol's ARITH(31) compiler option, if your problem is a plain lack of digits. |
Code: |
*process limits(fixeddec(15,31) fixedbin(31,63)); |
And don't be a smart-ass, and use
Code: |
*process limits(fixeddec(31,31) fixedbin(63,63)); |
|
|
Back to top |
|
|
swathykrishnan
New User
Joined: 01 Oct 2010 Posts: 43 Location: Bangalore
|
|
|
|
Hi Bill
Yes the user need it to get rounded for 2 digits even if its a vast number...
MULTIPLY or FLOAT DECIMAL will fix this issue... But we need to ROUND it... |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Hi,
Did you see Prino's last post? If you need more digits than you are "allowed", use the compiler option he has posted to give yourself access to more digits. Then you can define your fields as big enough for your purposes, and ROUND it to your heart's content. |
|
Back to top |
|
|
|