Author |
Message
|
EnOne |
Posted: Thu Oct 06, 2005 6:53 am Post subject: Padding a field |
|
|
 Centurion
Joined: 09 Oct 2002 Posts: 100 Location: Kansas City
|
One of the common things I am working on it Justifying and Padding within eSQL. There are a few ways to do this there are four examples below. For the example I'm using right justify left pad with zeros.
<InputNumber>123456</InputNumber>
A.
Code: |
DECLARE InputNumber CHAR;
SET InputNumber = CAST(InputBody.XML.InputNumber AS CHAR);
WHILE LENGTH(InputNumber) < 10 DO
SET InputNumber = '0' || InputNumber;
END WHILE;
|
B.
Code: |
DECLARE InputNumber CHAR;
SET InputNumber = SUBSTRING('0000000000' FROM 1 FOR (10-LENGTH(InputNumber))) || CAST(InputBody.InputNumber AS CHAR);
|
C.
Code: |
DECLARE InputInteger INT;
DECLARE InputNumber CHAR;
SET InputInteger = 10000000000 + InputBody.InputNumber;
SET InputNumber = SUBSTRING(CAST(InputInteger AS CHAR) FROM 2 FOR 10);
|
D.
Code: |
SET InputNumber = RIGHT('0000000000' || CAST(InputBody.InputNumber AS CHAR),10) |
Does anyone know a best practice for which way is faster/more reliable or is there another way. |
|
Back to top |
|
 |
Empeterson |
Posted: Thu Oct 06, 2005 6:58 am Post subject: |
|
|
Centurion
Joined: 14 Apr 2003 Posts: 125 Location: Foxboro, MA
|
There is an OVERLAY function which which can accomplish this. Refer to the esql manual for exact syntax. _________________ IBM Certified Specialist: MQSeries
IBM Certified Specalist: Websphere MQ Integrator |
|
Back to top |
|
 |
EnOne |
Posted: Thu Oct 06, 2005 7:34 am Post subject: |
|
|
 Centurion
Joined: 09 Oct 2002 Posts: 100 Location: Kansas City
|
E.
Code: |
DECLARE InputLength INT;
DECLARE InputNumber CHAR;
SET InputLength = LENGTH(InputRoot.InputNumber);
SET InputNumber = OVERLAY('0000000000' PLACING InputRoot.InputNumber FROM (10-InputLength) FOR InputLength);
|
|
|
Back to top |
|
 |
Empeterson |
Posted: Thu Oct 06, 2005 8:52 am Post subject: |
|
|
Centurion
Joined: 14 Apr 2003 Posts: 125 Location: Foxboro, MA
|
What are you doing with InputNumber? Is that going to be mapped to a field that is defined in a message set? _________________ IBM Certified Specialist: MQSeries
IBM Certified Specalist: Websphere MQ Integrator |
|
Back to top |
|
 |
EnOne |
Posted: Thu Oct 06, 2005 9:24 am Post subject: |
|
|
 Centurion
Joined: 09 Oct 2002 Posts: 100 Location: Kansas City
|
They are receiving the number from me in XML format. The Input is either MRM or XML.
<Parent>
<OutputNumber>0000123456</OutputNumber>
</Parent> |
|
Back to top |
|
 |
|