|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Using ESQL to validate a valid numeric amount |
« View previous topic :: View next topic » |
Author |
Message
|
AlexeiSkate |
Posted: Thu Jun 27, 2002 12:59 pm Post subject: Using ESQL to validate a valid numeric amount |
|
|
Centurion
Joined: 10 Apr 2002 Posts: 123
|
I have an XML message with a transactionAmoung tag. I need to validate in filter node that the amount value is numeric and does not equal to 0. I'm assuming that the amount will come in as a STRING format. Does anyone know how I can use ESQL to perform such validation ?
thanks,
Alex |
|
Back to top |
|
 |
kirani |
Posted: Thu Jun 27, 2002 4:41 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
As long as Amount field has numeric data in it, you can use CAST function to cast it to an Integer data type before comparing with 0. _________________ 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 |
|
 |
AlexeiSkate |
Posted: Sun Jun 30, 2002 6:25 am Post subject: |
|
|
Centurion
Joined: 10 Apr 2002 Posts: 123
|
Thanks Kirani.
But if I first need to check if the data is numeric, then would I have to examine character by character ? For instance if the amount field has '120B.50', would I need to have something like a for loop to check that each character can be cast to an interger ? |
|
Back to top |
|
 |
kolban |
Posted: Sun Jun 30, 2002 7:46 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2001 Posts: 1072 Location: Fort Worth, TX, USA
|
What happens when you try and cast a non-numeric string to a numeric? My guess is that it would return null. So your logic could be to test for !null and value of 0. |
|
Back to top |
|
 |
kirani |
Posted: Sun Jun 30, 2002 10:23 am Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
Neil:
I have tested this. If we try to cast non-numeric string to a numeric, it will return a value of 0. So we should check for value 0.
Alex:
Lets say your amount field has value '120B.50', then you should do something like this,
DECLARE AMT FLOAT;
SET AMT = CAST(InputRoot.XML.....);
IF ( AMT = 0 ) THEN
-- inValid Amount Processing goes here
ELSE
-- Valid Amount processing goes here
END IF;
But, if your amount is 0 in input message, as per this logic it will tell you amount is not valid. Are you expecting amount as 0 in input message? _________________ 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 |
|
 |
TonyG |
Posted: Thu Sep 19, 2002 12:12 pm Post subject: |
|
|
Newbie
Joined: 16 Jul 2002 Posts: 4 Location: UK
|
Hi,
Iam using v2.02 of MQSI and I cant get the example code above to work.
I have an input message :
<ZOO><Number1>111111</Number1><Number2>37c4632a897</Number2><Number3>d</Number3><Number4>0</Number4></ZOO>
Which I put onto my input queue with an RFH2 header, specifying message name and domain of XML, using rfhutil.exe utility.
The flow has one compute node :
DECLARE v_Amount FLOAT;
SET v_Amount = 99;
SET v_Amount = CAST(InputRoot.XML.ZOO.Number1 AS FLOAT);
IF v_Amount = 0 THEN
SET OutputRoot.XML.ZOO.ZERO1 = 'Y';
END IF;
SET OutputRoot.XML.ZOO.Amount1 = CAST(v_Amount AS CHARACTER);
SET v_Amount = CAST(InputRoot.XML.ZOO.Number2 AS FLOAT);
SET OutputRoot.XML.ZOO.Amount2 = CAST(v_Amount AS CHARACTER);
IF v_Amount = 0 THEN
SET OutputRoot.XML.ZOO.ZERO2 = 'Y';
END IF;
SET v_Amount = CAST(InputRoot.XML.ZOO.Number3 AS FLOAT);
SET OutputRoot.XML.ZOO.Amount3 = CAST(v_Amount AS CHARACTER);
IF v_Amount = 0 THEN
SET OutputRoot.XML.ZOO.ZERO3 = 'Y';
END IF;
SET v_Amount = CAST(InputRoot.XML.ZOO.Number4 AS FLOAT);
SET OutputRoot.XML.ZOO.Amount4 = CAST(v_Amount AS CHARACTER);
IF v_Amount = 0 THEN
SET OutputRoot.XML.ZOO.ZERO4 = 'Y';
END IF;
And I get this output :
<ZOO>
<Number1>111111</Number1>
<Number2>37c4632a897</Number2>
<Number3>d</Number3>
<Number4>0</Number4>
<Amount1>1.11111E+5</Amount1>
<Amount2>3.7E+1</Amount2>
<Amount3>0E0</Amount3>
<ZERO3>Y</ZERO3>
<Amount4>0E0</Amount4>
<ZERO4>Y</ZERO4>
</ZOO>
.. So 37c4632a897 was cast to float 3.7E+1
If I CAST AS INTEGER instead of FLOAT I get
ConversionException BIP2595E: Error casting character string '37c4632a8970000' to an integer.
An attempt was made to cast the character string '37c4632a8970000' to an integer, but the string was of the wrong format.
I'm not sure where the unprintable characters come from
Any help on this would be much appreciated
Thanks,
Tony |
|
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
|
|
|
|