ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » A DECIMAL Precision Problem when I use ASBITSTREAM with MRM

Post new topic  Reply to topic
 A DECIMAL Precision Problem when I use ASBITSTREAM with MRM « View previous topic :: View next topic » 
Author Message
MizukiYamato
PostPosted: Thu Feb 14, 2013 1:59 am    Post subject: A DECIMAL Precision Problem when I use ASBITSTREAM with MRM Reply with quote

Apprentice

Joined: 16 Dec 2009
Posts: 45
Location: Japan

Hi all,

I am facing a problem when I use ESQL ASBITSTREAM function.

ESQL:
Code:

-- DECLARE DECIMAL element.
CREATE LASTCHILD of Environment.Variables.MRM DOMAIN('MRM') Name 'Test';
SET Environment.Variables.MRM.Test.c = CAST('4.0' AS DECIMAL FORMAT('##0.0'));

-- Use ASBITSTREAM to convert Environment tree to BLOB.
DECLARE TEST BLOB ASBITSTREAM(Environment.Variables.MRM.Test ENCODING 546 CCSID 1208 OPTIONS RootBitStream
SET 'EnvironmentMsgSet' TYPE 'Test' FORMAT 'XML1' );


configuration of XML1(XML Wire Format) of the Message Set:
Code:

Output policy for xsi:type attributes = Always (All elements)
(To store type information, I checked this.)


I expect that the value of Test.c should be <c xsi:type="xsd:decimal">4.0</c>
, but actually, the value was <c xsi:type="xsd:decimal">4</c> .


at WMB 8.0.0.1 (WMBT 8.0.0.1 ifix 002)

Back to top
View user's profile Send private message
mqjeff
PostPosted: Thu Feb 14, 2013 4:14 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Please don't use MRM for XML.

Use XMLNSC.
Back to top
View user's profile Send private message
kimbert
PostPosted: Thu Feb 14, 2013 4:50 am    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

Please explain why you are using MRM.
Back to top
View user's profile Send private message
MizukiYamato
PostPosted: Thu Feb 14, 2013 8:12 am    Post subject: Reply with quote

Apprentice

Joined: 16 Dec 2009
Posts: 45
Location: Japan

Thank you for youy reply.


Quote:
Please don't use MRM for XML.
Use XMLNSC.

Quote:
Please explain why you are using MRM.


I have to store Environment tree witch have elements and them types.
(I do not have to store namespace information)
And, I have to restore Environment tree from BLOB in Database.

[1]
First, I tried XMLNSC to store Environment tree.
But I could not store types of elements.

Code:

-- DECLARE DECIMAL element.
CREATE LASTCHILD of Environment.Variables.XMLNSC DOMAIN('XMLNSC') Name 'Test';
SET Environment.Variables.XMLNSC.Test.c = CAST('4.0' AS DECIMAL FORMAT('##0.0'));

-- Use ASBITSTREAM to convert Environment tree to BLOB.
DECLARE TEST BLOB ASBITSTREAM(Environment.Variables.XMLNSC.Test ENCODING 546 CCSID 1208 OPTIONS FolderBitStream); 


The value of Test.c was <c>4.0</c>.
But, I have to restore Environment tree from BLOB data.

the type of Test.c was xsd:string.(not xsd:decimal)
(same problem was mentioned in http://www.mqseries.net/phpBB2/viewtopic.php?t=19429
Quote:

Now, my only problem is going through the rest of the code to see where/how MsgType is used, because under the old method the value was an Integer. Now, it's become Character.


)

[2]
To store the information of types, I used MRM XML parser.
I could store the information of types, but the problem has occuring about precision of decimal.
Back to top
View user's profile Send private message
rekarm01
PostPosted: Fri Feb 15, 2013 3:12 am    Post subject: Re: A DECIMAL Precision Problem when I use ASBITSTREAM with Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 1415

MizukiYamato wrote:
Code:
SET Environment.Variables.MRM.Test.c = CAST('4.0' AS DECIMAL FORMAT('##0.0'));

The FORMAT clause applies to the string ('4.0'), not to the resulting decimal (...MRM.Test.c). Numeric data types do not have a user-specifiable format. To preserve the desired format, take out the CAST:

Code:
SET Environment.Variables.MRM.Test.c = '4.0';

The MRM parser can get the xsi:type from the message model.

MizukiYamato wrote:
First, I tried XMLNSC to store Environment tree.
But I could not store types of elements.

The XMLNSC parser won't automatically add an xsi:type attribute, but it's easy enough to do in ESQL:

Code:
SET Environment.Variables.XMLNSC.Test.c = '4.0';
SET Environment.Variables.XMLNSC.Test.c.(XMLNSC.Attribute)xsi:type = 'xsd:decimal';

(assuming the namespaces are also suitably declared).

MizukiYamato wrote:
I could store the information of types, but the problem has occuring about precision of decimal.

That extra precision only applies to the lexical representation (string), not to the actual value (decimal). Any sort of conversion from string to decimal back to string may fail to preserve the original representation.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Fri Feb 15, 2013 5:44 am    Post subject: Re: A DECIMAL Precision Problem when I use ASBITSTREAM with Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

rekarm01 wrote:
MizukiYamato wrote:
I could store the information of types, but the problem has occuring about precision of decimal.

That extra precision only applies to the lexical representation (string), not to the actual value (decimal). Any sort of conversion from string to decimal back to string may fail to preserve the original representation.


This is the important bit. The internal representation of a decimal has no notion of an arbitrary physical format. It contains the logical value "4", which is exactly and mathematically equivalent to "4.0" and "04.0" and "00004.0000000000000000000"

If you need a physical output of "4.0", you need to ensure that your message model indicates that when the logical value is serialized, it is serialized to a format that has at least one 0 after the decimal point.

This is done in the XSD that models the XML document.

If your XSD indicates that the physical field is a string, then you can use the CAST of a DECIMAL value INTO a CHARACTER to indicate this.

Please use the XMLNSC parser!

Please do not use MRM for XML data.
Back to top
View user's profile Send private message
rekarm01
PostPosted: Fri Feb 15, 2013 10:42 am    Post subject: Re: A DECIMAL Precision Problem when I use ASBITSTREAM with Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 1415

mqjeff wrote:
If you need a physical output of "4.0", you need to ensure that your message model indicates that when the logical value is serialized, it is serialized to a format that has at least one 0 after the decimal point.

This is done in the XSD that models the XML document.

Can this be done in the XSD? The XSD can specify a pattern constraint, for a suitably derived type of xsd:decimal (or xsd:string), but this only affects the input validation, not the output format. The parser can convert decimal to string, but how would it apply a specified format?

MizukiYamato wrote:
... the problem has occuring about precision of decimal.

More importantly though, does the BLOB data itself really need to preserve the original format? A subsequent CAST can always apply the desired format later, when restoring the Environment tree from BLOB data.
Back to top
View user's profile Send private message
MizukiYamato
PostPosted: Sat Feb 16, 2013 9:28 am    Post subject: Reply with quote

Apprentice

Joined: 16 Dec 2009
Posts: 45
Location: Japan

Thank you rekarm01 and mqjeff.

I researched about the WMB's data binding about xsd:decimal.

[1]
message flow:
Code:

SOAP Input -> Trace
(The schema(XSD) of input data has xsd:decimal.)


Result:
Code:

Input data of the decimal part: demo:A>10.000</demo:A>
Output data of the decimal part: (0x03000000:PCDataField)http://demo:A = 10 (DECIMAL)



[2]
message flow:
Code:

... -> Compute -> Trace

at Compute node, I wrote:
SET Environment.Variables.Test.c = 4.0;


Result:
Code:

Output data of the decimal part: ((0x03000000:NameValue):c   = 4.0 (DECIMAL)



According to above results, I think that databinding of decimal cannot preserve its precision, too.
(But, from perspective of interoperability, this might be awaiting solution)

So, I have to use xsd:string when I have to preserve precision.


Quote:
Please use the XMLNSC parser!

Please do not use MRM for XML data.

Yes, I will do below:
Code:

[store]
1. Receive environment tree to save.
2. Convert any element type to CHARACTER type and
    set (XMLNSC.Attribute)xsi:type.
3. Use ASBITSTREAM function with XMLNSC.
4. Store converted BLOB.

[restore]
1. Restore converted BLOB.
2. Use CREATE function with XMLNSC.
3. Convert CHARACTER type to some element type which have (XMLNSC.Attribute)xsi:type.
4. Send environment tree.
Back to top
View user's profile Send private message
rekarm01
PostPosted: Sat Feb 16, 2013 2:55 pm    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 1415

MizukiYamato wrote:
According to above results, I think that databinding of decimal cannot preserve its precision, too.
(But, from perspective of interoperability, this might be awaiting solution)

To ensure interoperability, don't impose any constraints beyond what the standard actually requires. The ESQL DECIMAL data type includes a precision (and scale), but the xsd:decimal data type does not:

Quote:
... Precision is not reflected in this value space; the number 2.0 is not distinct from the number 2.00. ...

Although the xsd:decimal data type has constraining facets for totalDigits and fractionDigits, these only apply to derived data types, only constrain the maximum number of digits, and only constrain the value space, not the lexical representation.

MizukiYamato wrote:
So, I have to use xsd:string when I have to preserve precision.

Technically, that would be ESQL CHARACTER, not xsd:string. If preserving the input representation is really necessary, then that's the simplest way to do it.
Back to top
View user's profile Send private message
MizukiYamato
PostPosted: Sun Feb 17, 2013 5:07 am    Post subject: Reply with quote

Apprentice

Joined: 16 Dec 2009
Posts: 45
Location: Japan

Quote:
Although the xsd:decimal data type has constraining facets for totalDigits and fractionDigits, these only apply to derived data types, only constrain the maximum number of digits, and only constrain the value space, not the lexical representation.


Oh, I see! I understand.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » A DECIMAL Precision Problem when I use ASBITSTREAM with MRM
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.