ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » HEX representation of a alpha numberic string in ESQL

Post new topic  Reply to topic
 HEX representation of a alpha numberic string in ESQL « View previous topic :: View next topic » 
Author Message
kuladeep.dairy
PostPosted: Wed Nov 11, 2009 4:19 pm    Post subject: HEX representation of a alpha numberic string in ESQL Reply with quote

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
View user's profile Send private message
kirani
PostPosted: Wed Nov 11, 2009 4:53 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
kuladeep.dairy
PostPosted: Wed Nov 11, 2009 4:56 pm    Post subject: Reply with quote

Apprentice

Joined: 11 Jul 2009
Posts: 38

Kiran,
i did it. it gives me the same string as the input!!
Back to top
View user's profile Send private message
zpat
PostPosted: Thu Nov 12, 2009 1:03 am    Post subject: Reply with quote

Jedi Council

Joined: 19 May 2001
Posts: 5853
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
View user's profile Send private message
kimbert
PostPosted: Thu Nov 12, 2009 1:51 am    Post subject: Reply with quote

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
View user's profile Send private message
kuladeep.dairy
PostPosted: Sun Nov 15, 2009 10:52 pm    Post subject: Reply with quote

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
View user's profile Send private message
kimbert
PostPosted: Mon Nov 16, 2009 2:26 am    Post subject: Reply with quote

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
View user's profile Send private message
zpat
PostPosted: Mon Nov 16, 2009 3:39 am    Post subject: Reply with quote

Jedi Council

Joined: 19 May 2001
Posts: 5853
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
View user's profile Send private message
elvis_gn
PostPosted: Mon Nov 16, 2009 4:31 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
kimbert
PostPosted: Mon Nov 16, 2009 5:16 am    Post subject: Reply with quote

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
View user's profile Send private message
kuladeep.dairy
PostPosted: Thu Nov 19, 2009 2:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
Vitor
PostPosted: Thu Nov 19, 2009 2:35 pm    Post subject: Reply with quote

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
View user's profile Send private message
kuladeep.dairy
PostPosted: Fri Nov 20, 2009 1:50 pm    Post subject: Having reviewed and given due weight to the discussions on t Reply with quote

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
View user's profile Send private message
smdavies99
PostPosted: Fri Nov 20, 2009 3:34 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » HEX representation of a alpha numberic string in ESQL
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.