Author |
Message
|
hellobond070 |
Posted: Mon Aug 16, 2010 4:19 pm Post subject: Number Formatting to output MRM |
|
|
 Centurion
Joined: 18 Nov 2009 Posts: 118
|
I have got a issue with data formatting.
Input is an XML files with one of the data element passing the value say '54.34'.
I need this to be formatted in 10 characters including the dot.
so the output should look like '0000054.34'
I tried
Code: |
DECLARE pattern CHARACTER '0000000.00'; |
and then used CAST
Code: |
SET OutputRoot.MRM.SKU_QTY = CAST(source AS CHARACTER FORMAT pattern); |
where source is the input xml element.
I am getting the below error :
Quote: |
(0x01000000:Name ):ParserException = (
(0x03000000:NameValue):File = 'F:\build\S610_P\src\MTI\MTIforBroker\MtiImbParser2\MtiImbValueValidator.cpp' (CHARACTER)
(0x03000000:NameValue):Line = 1859 (INTEGER)
(0x03000000:NameValue):Function = 'MtiImbValueValidator::basicValidate' (CHARACTER)
(0x03000000:NameValue):Type = '' (CHARACTER)
(0x03000000:NameValue):Name = '' (CHARACTER)
(0x03000000:NameValue):Label = '' (CHARACTER)
(0x03000000:NameValue):Catalog = 'BIPv610' (CHARACTER)
(0x03000000:NameValue):Severity = 3 (INTEGER)
(0x03000000:NameValue):Number = 5164 (INTEGER)
(0x03000000:NameValue):Text = 'Exception thrown when casting to the expected logical type' (CHARACTER)
(0x01000000:Name ):Insert = (
(0x03000000:NameValue):Type = 5 (INTEGER)
(0x03000000:NameValue):Text = 'SKU_QTY' (CHARACTER)
)
(0x01000000:Name ):Insert = (
(0x03000000:NameValue):Type = 5 (INTEGER)
(0x03000000:NameValue):Text = 'INTEGER' (CHARACTER)
)
(0x01000000:Name ):Insert = (
(0x03000000:NameValue):Type = 5 (INTEGER)
(0x03000000:NameValue):Text = 'STRING' (CHARACTER)
)
(0x01000000:Name ):Insert = (
(0x03000000:NameValue):Type = 5 (INTEGER)
(0x03000000:NameValue):Text = '54.0' (CHARACTER)
)
(0x01000000:Name ):ConversionException = (
(0x03000000:NameValue):File = 'F:\build\S610_P\src\cpi\bsutils\datacnv.cpp' (CHARACTER)
(0x03000000:NameValue):Line = 621 (INTEGER)
(0x03000000:NameValue):Function = 'DataCnv::StrToInt64' (CHARACTER)
(0x03000000:NameValue):Type = '' (CHARACTER)
(0x03000000:NameValue):Name = '' (CHARACTER)
(0x03000000:NameValue):Label = '' (CHARACTER)
(0x03000000:NameValue):Catalog = 'BIPv610' (CHARACTER)
(0x03000000:NameValue):Severity = 3 (INTEGER)
(0x03000000:NameValue):Number = 5505 (INTEGER)
(0x03000000:NameValue):Text = 'CPI Converter Input Data Invalid' (CHARACTER)
(0x01000000:Name ):Insert = (
(0x03000000:NameValue):Type = 5 (INTEGER)
(0x03000000:NameValue):Text = 'string' (CHARACTER)
)
(0x01000000:Name ):Insert = (
(0x03000000:NameValue):Type = 5 (INTEGER)
(0x03000000:NameValue):Text = '54.0' (CHARACTER)
)
)
) |
Please advise. |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Aug 16, 2010 7:40 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
For the format you gave, you would need to cast to a double. That format is decimal and as such not castable to an Integer.  _________________ MQ & Broker admin |
|
Back to top |
|
 |
hellobond070 |
Posted: Mon Aug 16, 2010 8:43 pm Post subject: |
|
|
 Centurion
Joined: 18 Nov 2009 Posts: 118
|
So should it be as below
Quote: |
DECLARE pattern DOUBLE '0000000.00'; |
OR
SET OutputRoot.MRM.SKU_QTY = CAST(source AS DOUBLE FORMAT pattern);
Please suggest. |
|
Back to top |
|
 |
hellobond070 |
Posted: Tue Aug 17, 2010 7:13 am Post subject: |
|
|
 Centurion
Joined: 18 Nov 2009 Posts: 118
|
I read a few posts and I feel this kind of conversion is not possible.
Let me redefine my problem
Input is XML file which I parse using XMLNSC. Suppose one of the element quantitiy has "54.0", the output is a CWF MRM.
The output field should look like "00000054.00" which is of 10 characters.
Can someone still advise if they it is possible |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Aug 17, 2010 9:50 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
That should all be possible.
Just remember that casting if often a matter of logic and perception.
So you can cast a double or integer to a format "000.00" but you can cast "53.55" or "54.00" only to a double. You can then cast that double to an integer, loosing some precision...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
kimbert |
Posted: Mon Aug 23, 2010 2:57 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
Let me redefine my problem
Input is XML file which I parse using XMLNSC. |
Being picky, the input format is not relevant. The MRM CWF writer will produce an output bitstream using the the message tree and the message set.
Quote: |
Suppose one of the element quantitiy has "54.0" |
Which data type is this. Is it a string or a decimal or a float?
Hint: if you have not set the XMLNSC parser option 'Build tree using XML schema' then it will be a string.
Quote: |
The output field should look like "00000054.00" which is of 10 characters. |
That looks like a number that has been written with two decimal places, right-justified and padded with zeros. You need to:
a) CAST the input CHARACTER to a decimal or float. You can't control the output format accurately unless you first convert the string to a number.
b1) CAST the resulting number to a CHARACTER using CAST with a FORMAT clause.
or
b2) put the float/decimal into OutputRoot.MRM.xxx and change your message definition file to expect a number. Set the CWF properties to control the number of decimal places and the padding/justification.
b2) would be my choice, because it removes physical formatting from the message flow and puts it where it belongs ( in the message set ).
If you have a schema for your input XML then you can enable validation, set 'Build tree using XML Schema' and avoid having to do the CAST in a). |
|
Back to top |
|
 |
|