Author |
Message
|
kuladeep.dairy |
Posted: Wed Nov 11, 2009 4:19 pm Post subject: HEX representation of a alpha numberic string in ESQL |
|
|
Apprentice
Joined: 11 Jul 2009 Posts: 38
|
How do we implement an ESQL funtion(template given below) that converts a string of characters
to correcponding HEX string.
for example:
input:NZA00002939
ouput: 4E5A413030303032393339
CREATE FUNCTION XYZ(IN inStr CHAR ) RETURNS CHAR
BEGIN
RETURN outStr;
END; |
|
Back to top |
|
 |
kirani |
Posted: Wed Nov 11, 2009 4:53 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
Have you tried converting this string to a BLOB datatype? _________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
kuladeep.dairy |
Posted: Wed Nov 11, 2009 4:56 pm Post subject: |
|
|
Apprentice
Joined: 11 Jul 2009 Posts: 38
|
Kiran,
i did it. it gives me the same string as the input!! |
|
Back to top |
|
 |
zpat |
Posted: Thu Nov 12, 2009 1:03 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
The hex values depends on whether the string is ASCII, EBCDIC, Unicode etc.
You want printable hex, rather than internal hex (or BLOB).
You may have to convert based on two arrays of 256 values - one of internal hex and one of printable hex.
There must be a way to optimise this but I can't think of one offhand. |
|
Back to top |
|
 |
kimbert |
Posted: Thu Nov 12, 2009 1:51 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
When talking about CASTing BLOB to CHARACTEr, the docs http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r1m0/topic/com.ibm.etools.mft.doc/ak05680_.htm say:
Quote: |
The result is a string conforming to the definition of a binary string literal whose interpreted value is the same as the source value. The resulting string has the form X'hhhh' (where h is any hexadecimal character).
If you specify either a CCSID or ENCODING clause, the byte array is assumed to be characters in the specified CCSID and encoding, and is code-page converted into the character return value. |
So you need something like
Code: |
SET myBLOBAsString = CAST myBLOB AS CHARACTER; |
Note to future readers: Normally you should supply the CCSID and ENCODING parameters as well. In this case, kuladeep.dairy specifically wants the raw hex bytes to be converted to a string of UTF-16 hexadecimal digit characters. |
|
Back to top |
|
 |
kuladeep.dairy |
Posted: Sun Nov 15, 2009 10:52 pm Post subject: |
|
|
Apprentice
Joined: 11 Jul 2009 Posts: 38
|
My code looks like this:
DECLARE pn CHARACTER 'NZA00002939';
DECLARE myblob1 BLOB CAST( pn AS BLOB);
Zpat, you are saying that i will have to go thru pn string character by character and convert them to corresponding printablehex characters
like
N Z A 0 0 0 0 2 9 3 9
4E 5A 41 30 30 30 30 32 39 33 39. |
|
Back to top |
|
 |
kimbert |
Posted: Mon Nov 16, 2009 2:26 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Please explain what you are trying to do. It sounds as if there should be a much simpler solution. |
|
Back to top |
|
 |
zpat |
Posted: Mon Nov 16, 2009 3:39 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
One way is to have a 256 element array of the two byte printable hex values. ''00','01','02','03','04', etc to 'FF'
Take the internal byte value - convert to decimal (range 0-255) and use as the index (subscript) into the printable array to find the printable version. |
|
Back to top |
|
 |
elvis_gn |
Posted: Mon Nov 16, 2009 4:31 am Post subject: |
|
|
 Padawan
Joined: 08 Oct 2004 Posts: 1905 Location: Dubai
|
Hi kuladeep.dairy,
If the ESQL options are getting complex, use a java static method to do the conversion for you.
Regards. |
|
Back to top |
|
 |
kimbert |
Posted: Mon Nov 16, 2009 5:16 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
One way is to have a 256 element array of the two byte printable hex values. ''00','01','02','03','04', etc to 'FF' |
I don't understand why that is better than what ESQL offers ( for free ) via the CAST statement.
I still don't know *why* kuldeep.dairy want to do this. It sounds like something that a parser should be doing. |
|
Back to top |
|
 |
kuladeep.dairy |
Posted: Thu Nov 19, 2009 2:21 pm Post subject: |
|
|
Apprentice
Joined: 11 Jul 2009 Posts: 38
|
Kibmert,
I was trying to create a correaltion id based on an alpha numeric string.
Many Thanks. |
|
Back to top |
|
 |
Vitor |
Posted: Thu Nov 19, 2009 2:35 pm Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
kuladeep.dairy wrote: |
I was trying to create a correaltion id based on an alpha numeric string. |
Having reviewed and given due weight to the discussions on the forum on the issues surrounding non-system generated ids of course. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
kuladeep.dairy |
Posted: Fri Nov 20, 2009 1:50 pm Post subject: Having reviewed and given due weight to the discussions on t |
|
|
Apprentice
Joined: 11 Jul 2009 Posts: 38
|
Vitor,
am sorry. i went through other topics on this, but i couldnt get any answers. can you please let me creating correlid from application specific data is advisable? if so how can we do it?
Many Thanks. |
|
Back to top |
|
 |
smdavies99 |
Posted: Fri Nov 20, 2009 3:34 pm Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
I guess what vitor is trying to say that yes you can generate your own MsgId & CorrelId values there are some major considerations around the uniqueness of the values that have to be fully understood before anything is implemented.
Using WMQ generated values does this for you.
There are posts here that discuss the actual method of creating these fields but in most cases generating your own is a bad idea. _________________ 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 |
|
 |
|