Author |
Message
|
Aldrine |
Posted: Mon Jul 25, 2011 4:29 am Post subject: Base Conversion from Decimal to Octal and likewise |
|
|
 Novice
Joined: 25 Jul 2011 Posts: 22 Location: India
|
How do i convert Decimal input of base 10 to various other bases like
Hexadecimal (Base 16)
Octal (Base 8 ).
In java we could directly convert the code using the toString(long i, int radix) but in ESQL how to achieve the same effect?
Example:
System.out.println(Long.toString(45, 16)); //26
System.out.println(Long.toString(45, 8 )); //55
System.out.println(Long.toString(45, 9)); //50
Last edited by Aldrine on Mon Jul 25, 2011 10:10 pm; edited 1 time in total |
|
Back to top |
|
 |
lancelotlinc |
Posted: Mon Jul 25, 2011 4:45 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
|
Back to top |
|
 |
Aldrine |
Posted: Tue Jul 26, 2011 2:46 am Post subject: |
|
|
 Novice
Joined: 25 Jul 2011 Posts: 22 Location: India
|
lancelotlinc wrote: |
Why not you use a Java compute node, since you already have the source code to do it in Java? |
Thanks for the insight, but my project is migration of java code from eGate to ESQL in WMB. Hence i am trying my best to avoild Java Node.
As a work around am using the following code:
Code: |
CREATE FUNCTION ConvertBase (
IN InputInteger INTEGER,
IN InputRadix INTEGER
) RETURNS CHARACTER
BEGIN
DECLARE OutputText CHARACTER REPLICATE('0', 65);
DECLARE digitsArray CHARACTER '01234567890abcdefghijklmnopqrstuvwxyz';
IF (InputRadix < 2) OR (InputRadix > 36) THEN
SET InputRadix = 10;
END IF;
DECLARE i INTEGER 65;
DECLARE j INTEGER 0;
IF InputInteger < 0 THEN
SET j = 1;
END IF;
IF j = 0 THEN
SET InputInteger = -InputInteger;
END IF;
DECLARE ReplaceString CHARACTER;
WHILE InputInteger <= -InputRadix DO
SET ReplaceString = SUBSTRING ( digitsArray FROM -(MOD (InputInteger,InputRadix )-1) FOR 1);
SET OutputText = OVERLAY ( OutputText PLACING ReplaceString FROM i for 1 );
SET InputInteger = InputInteger / InputRadix;
SET i = i - 1;
END WHILE;
SET ReplaceString = SUBSTRING ( digitsArray FROM -(InputInteger-1) FOR 1);
SET OutputText = OVERLAY ( OutputText PLACING ReplaceString FROM i for 1 );
IF j <> 0 THEN
SET i = i - 1;
SET OutputText = OVERLAY ( OutputText PLACING '-' FROM i for 1 );
END IF;
RETURN SUBSTRING(OutputText FROM i);
END; |
Example:
Code: |
SET Output = ConvertBase ( 45, 8 ); /* 55 */
SET Output = ConvertBase ( 45, 16 ); /* 2d */
SET Output = ConvertBase ( 45, 2 ); /* 101101 */
SET Output = ConvertBase ( 45, 10 ); /* 45 */ |
I am looking for a much simpler solution?
Regards,
Aldrine Einsteen |
|
Back to top |
|
 |
smdavies99 |
Posted: Tue Jul 26, 2011 4:06 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
How about calling the Java Class directly from ESQL? _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
Aldrine |
Posted: Tue Jul 26, 2011 4:18 am Post subject: |
|
|
 Novice
Joined: 25 Jul 2011 Posts: 22 Location: India
|
smdavies99 wrote: |
How about calling the Java Class directly from ESQL? |
As i said earlier, am trying to make the migration Java free. _________________ --
Aldrine Einsteen |
|
Back to top |
|
 |
lancelotlinc |
Posted: Tue Jul 26, 2011 4:44 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
Aldrine wrote: |
lancelotlinc wrote: |
Why not you use a Java compute node, since you already have the source code to do it in Java? |
Thanks for the insight, but my project is migration of java code from eGate to ESQL in WMB. Hence i am trying my best to avoild Java Node.
As a work around am using the following code:
Code: |
CREATE FUNCTION ConvertBase (
IN InputInteger INTEGER,
IN InputRadix INTEGER
) RETURNS CHARACTER
BEGIN
DECLARE OutputText CHARACTER REPLICATE('0', 65);
DECLARE digitsArray CHARACTER '01234567890abcdefghijklmnopqrstuvwxyz';
IF (InputRadix < 2) OR (InputRadix > 36) THEN
SET InputRadix = 10;
END IF;
DECLARE i INTEGER 65;
DECLARE j INTEGER 0;
IF InputInteger < 0 THEN
SET j = 1;
END IF;
IF j = 0 THEN
SET InputInteger = -InputInteger;
END IF;
DECLARE ReplaceString CHARACTER;
WHILE InputInteger <= -InputRadix DO
SET ReplaceString = SUBSTRING ( digitsArray FROM -(MOD (InputInteger,InputRadix )-1) FOR 1);
SET OutputText = OVERLAY ( OutputText PLACING ReplaceString FROM i for 1 );
SET InputInteger = InputInteger / InputRadix;
SET i = i - 1;
END WHILE;
SET ReplaceString = SUBSTRING ( digitsArray FROM -(InputInteger-1) FOR 1);
SET OutputText = OVERLAY ( OutputText PLACING ReplaceString FROM i for 1 );
IF j <> 0 THEN
SET i = i - 1;
SET OutputText = OVERLAY ( OutputText PLACING '-' FROM i for 1 );
END IF;
RETURN SUBSTRING(OutputText FROM i);
END; |
Example:
Code: |
SET Output = ConvertBase ( 45, 8 ); /* 55 */
SET Output = ConvertBase ( 45, 16 ); /* 2d */
SET Output = ConvertBase ( 45, 2 ); /* 101101 */
SET Output = ConvertBase ( 45, 10 ); /* 45 */ |
I am looking for a much simpler solution?
Regards,
Aldrine Einsteen |
SO you are avoiding the best possible solution because someone told you to? What is so bad about Java Compute Nodes? Do they have cooteys? _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
Vitor |
Posted: Tue Jul 26, 2011 4:54 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
lancelotlinc wrote: |
SO you are avoiding the best possible solution because someone told you to? |
I suspect the person that said it is either responsible for end of year reviews or payment of invoices. Remember that most people are not in your privlidged position and have to do what we're told.
More or less. With optional teeth grinding. Picking our battles and other soundbites.
lancelotlinc wrote: |
What is so bad about Java Compute Nodes? Do they have cooteys? |
Aside from my personal view, the OP mentioned eGate. Having written code in Monk (and I still sometimes wake screaming that "the brackets are going to get me") and seen the "improved" Java interface, I can understand why they're trying to move as far away from it as possible. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Aldrine |
Posted: Tue Jul 26, 2011 4:57 am Post subject: |
|
|
 Novice
Joined: 25 Jul 2011 Posts: 22 Location: India
|
Somemore back ground information to understand my need.
I am currently into a pilot project we are doing two projects parallely: (ESQL and Java{which is migrated through migration engine from eGate}).
Those two would be later compared on based on Performance, endurance and stability, even maintainability to choose for future projects.
The need for optimized ESQL code for Base conversion is standing impervious to Java's best solution  _________________ --
Aldrine Einsteen |
|
Back to top |
|
 |
lancelotlinc |
Posted: Tue Jul 26, 2011 6:09 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
Aldrine wrote: |
The need for optimized ESQL code for Base conversion is standing impervious to Java's best solution  |
Last time I checked, WMB can use BOTH ESQL and Java in the same flow. Its not like you have to pick one to the exclusion of the other. _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
Vitor |
Posted: Tue Jul 26, 2011 6:12 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
lancelotlinc wrote: |
Aldrine wrote: |
The need for optimized ESQL code for Base conversion is standing impervious to Java's best solution  |
Last time I checked, WMB can use BOTH ESQL and Java in the same flow. Its not like you have to pick one to the exclusion of the other. |
Unless you're trying to remove the need for anyone on site who knows Java....  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
lancelotlinc |
Posted: Tue Jul 26, 2011 6:18 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
Vitor wrote: |
lancelotlinc wrote: |
Aldrine wrote: |
The need for optimized ESQL code for Base conversion is standing impervious to Java's best solution  |
Last time I checked, WMB can use BOTH ESQL and Java in the same flow. Its not like you have to pick one to the exclusion of the other. |
Unless you're trying to remove the need for anyone on site who knows Java....  |
You're right, sir Vitor. ESQL looks alot like Cobol. _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
Vitor |
Posted: Tue Jul 26, 2011 6:57 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
lancelotlinc wrote: |
ESQL looks alot like Cobol. |
You seriously, seriously need to lay off the caffine for a while.
ESQL looks nothing like COBOL, and requires a totally different skill set. I speak with authority, as one of my development staff is a 20-year COBOL man & he doesn't get it at all. Variables having "scope" is a concept that causes his eyes to glaze. Along with most of the other concepts.
But if they had eGate they've probably got a number of C/C++/C# people who could make the transition to ESQL. They could probably make the transition to Java as well, but as I said maybe there's head count reduction at work here. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
kimbert |
Posted: Tue Jul 26, 2011 7:04 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
ESQL is not going to do this particular task as elegantly as Java - that's why WMB allows ESQL to call out to Java for tasks like this. You should gently suggest to the decision-makers that, whatever the outcome of this trial, it is not wise to *ban* either ESQL or Java. It is OK to state that one or other is the preferred language on your site, as long as exception are allowed. |
|
Back to top |
|
 |
lancelotlinc |
Posted: Tue Jul 26, 2011 7:05 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
Vitor wrote: |
lancelotlinc wrote: |
ESQL looks alot like Cobol. |
You seriously, seriously need to lay off the caffine for a while. |
You right! I'm getting the shakes. _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
Vitor |
Posted: Tue Jul 26, 2011 7:22 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
kimbert wrote: |
it is not wise to *ban* either ESQL or Java. It is OK to state that one or other is the preferred language on your site, as long as exception are allowed. |
You can also mention that this one exception to an ESQL-only rule is a very stable piece of code with clearly defined & documentable inputs and output & very low levels of ongoing development and maintenance. So it's a good candidate for the one piece of surviving Java that sits in a corner & no-one on site understands how it works.
Unlike (pulling an example out of thin air) the entire error handling and retry logic built into all of the flows which is a problem if it's written in Java with no documentation apart from a few comments in the code and you then downsize everybody on site who knows Java with no notice, no warning and no handover!  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
|