|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
What would be the best way ( TRIM leading Zeros ) |
« View previous topic :: View next topic » |
Author |
Message
|
mq_developer |
Posted: Mon Jan 27, 2003 9:58 am Post subject: What would be the best way ( TRIM leading Zeros ) |
|
|
Voyager
Joined: 18 Feb 2002 Posts: 82
|
Gang,
I creating XML message from incoming MRM input fields , some of the input fields are defined as FLOAT ( ESQL data type) corresponds to V99 COMP-3 fields in COBOL .
Customer wants to have following transformation
0000111.00 to be 111.00 , similar lines if incoming value is zero
0000000.00 to be 0.00
Rightnow what i am doing is CAST (InputField as CHAR) and TRIM LEADING '0' from that , but this would work for all cases except in case of 0000000.00 where it would result in .00 instead of 0.00
Now am using a IF condition to handle Zero (0000000.00) cases , but doesnt look like a better way to me ....
Need your ideas on this .....
Regards,
Ram |
|
Back to top |
|
 |
yaakovd |
Posted: Mon Jan 27, 2003 11:23 am Post subject: |
|
|
Partisan
Joined: 20 Jan 2003 Posts: 319 Location: Israel
|
DECLARE I INT;
DECLARE C1 CHAR;
SET C1 = "InputRoot".<your input MRM element>;
SET I = CAST( SUBSTRING( C1 FROM 1 FOR POSITION('.' IN C1)-1 ) AS INT);
SET OutputRoot.XML."field_1" = CAST ( I AS CHAR) || SUBSTRING( C1 FROM POSITION('.' IN C1) );
All depends how much you trust on your input.
If you not sure that your input is numeric, you can use my code from topic
http://www.mqseries.net/phpBB2/viewtopic.php?t=7231 befor casting to INT.
It can be like this:
IF(POSITION('.' IN C1) = 0)THEN
-- remove this case if it impossible for you: input = 0000000000
-- or add what you want to do
ELSE
IF(POSITION('.' IN C1) > 1)THEN
SET I = CAST( SUBSTRING( C1 FROM 1 FOR POSITION('.' IN C1)-1 ) AS INT);
SET OutputRoot.XML."field_1" = CAST ( I AS CHAR) || SUBSTRING( C1 FROM POSITION('.' IN C1) );
ELSE
-- remove this case if it impossible for you: input = .000000000
-- or add what you want to do
END IF;
END IF; _________________ Best regards.
Yaakov
SWG, IBM Commerce, Israel |
|
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
|
|
|
|