|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Accumulating Decimals |
« View previous topic :: View next topic » |
Author |
Message
|
stevehn |
Posted: Tue Aug 06, 2002 6:49 am Post subject: Accumulating Decimals |
|
|
Newbie
Joined: 06 Aug 2002 Posts: 2
|
Hello,
I received an exception when trying to accumulate decimal values into a singel varaible.
In ESQL I had loop that was accumulating values in a message for example
DEFINE A DECIMAL;
DEFINE i INT;
WHILE i < 100 DO
SET A = A + CAST(B[i] AS DECIMAL);
SET i = i + 1
END WHILE;
In this sample B is the array of elements from my message containg 30 values
I received an exception like
2002-08-06 10:27:07.499060 19 RecoverableException BIP2449E: Arithmetic overflow evaluating expression '0000000000000000000000000035.087+0.138'.
As you can see, the first value of the expression ( A ) shows 28 Leading zeros! When I looked backwards in the log, I discovered that through each iteration of the loop, another leading zero was added!
I've been able to circumvent the issue by trimmin the leadin zeroes after each itereation.
Has anyone one else seen this? SHould I report it as a bug or is it a feature I'm not aware of?
Thanks
Steve H |
|
Back to top |
|
 |
kirani |
Posted: Tue Aug 06, 2002 12:25 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
Steve,
You are running into this problem because you are using DECIMAL datatype without any precision and scale. If you don't specify precision and scle while casting to DECIMAL, WMQI will default these values from input data itself. An error will be thrown after your accumulated number's precision/scale goes beyond the range.
You will have to use precision and scale while doing CAST to DECIMAL data types. Depending on your expected output number, you could set some values here.
For example,
Code: |
SET A = A + CAST(B[i] AS DECIMAL(15,3));
|
_________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
stevehn |
Posted: Thu Aug 08, 2002 5:21 am Post subject: |
|
|
Newbie
Joined: 06 Aug 2002 Posts: 2
|
Kirani,
Thank you. That did infact sovle the problem.
Steve H |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|