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 » Convert a hexbinary to a readable character

Post new topic  Reply to topic Goto page 1, 2  Next
 Convert a hexbinary to a readable character « View previous topic :: View next topic » 
Author Message
radhika.tharayil
PostPosted: Wed Apr 07, 2010 7:14 am    Post subject: Convert a hexbinary to a readable character Reply with quote

Newbie

Joined: 06 Apr 2010
Posts: 7

Hi

Can anyone help me with an ESQL code which converts the hexbinary string like shown below to its equivalent character format which is a readble. I dont want want to use a message set.

'4544495f4443343020203132353030303030303030303'

Please help
Back to top
View user's profile Send private message
Vitor
PostPosted: Wed Apr 07, 2010 10:27 am    Post subject: Re: Convert a hexbinary to a readable character Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

radhika.tharayil wrote:
Can anyone help me with an ESQL code which converts the hexbinary string like shown below to its equivalent character format which is a readble.


What didn't you like about the other solutions to this which have been posted here previous?
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
kimbert
PostPosted: Wed Apr 07, 2010 10:47 am    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

CAST the string of characters to a BLOB, and then CAST the BLOB to CHARACTER using the correct ccsid.

Hint: What is the CHARACTER form of a BLOB in ESQL? The infocenter has the answer.
Back to top
View user's profile Send private message
radhika.tharayil
PostPosted: Thu Apr 08, 2010 9:22 am    Post subject: Reply with quote

Newbie

Joined: 06 Apr 2010
Posts: 7

Can you please let me know the exact esql code... actually this hexbinary string i have got from my SAP Adapter which is working in ALE passthrough mode. The IDocStream field comes in as hexbinary as shown below.

I just want to read the first few bytes and convert it to character.

<IDocStreamData>4544495f444334302020313235303030303

Also how do i come to know the exact CCSID which i need to use
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Apr 08, 2010 9:25 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

radhika.tharayil wrote:
Can you please let me know the exact esql code...


Are you too good to accept hints? Or just can't be bothered to write the code (or search for it on the forum)?

radhika.tharayil wrote:
Also how do i come to know the exact CCSID which i need to use


The CCSID of any message in is the header. If the data's coming over TCP/IP then it's anyone's guess
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
radhika.tharayil
PostPosted: Thu Apr 08, 2010 9:39 am    Post subject: Reply with quote

Newbie

Joined: 06 Apr 2010
Posts: 7

My Code looks as below:

When i try converting back to the characteri get back the hexbinary string. Please help

DECLARE NS1 NAMESPACE 'http://www.ibm.com/xmlns/prod/websphere/j2ca/sap/sapgenericidocobject';
DECLARE InputXMLNSRef REFERENCE TO InputRoot.XMLNS.NS1:SapGenericIDocObject.IDocStreamData;

SET Environment.CanonicalHdrBlob = CAST(InputXMLNSRef AS BLOB CCSID InputRoot.MQMD.CodedCharSetId);
SET Environment.MessageDumpChr = CAST(Environment.CanonicalHdrBlob AS CHAR CCSID InputRoot.Properties.CodedCharSetId
ENCODING InputRoot.Properties.Encoding);
Back to top
View user's profile Send private message
kimbert
PostPosted: Thu Apr 08, 2010 11:32 am    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

See this: http://publib.boulder.ibm.com/infocenter/wmbhelp/v7r0m0/topic/com.ibm.etools.mft.doc/ak17840_.htm

Two more hints for you:
- When CASTing from CHARACTER to BLOB, you don't need to specify a CCSID ( the CHARACTER field is specifying byte values, not characters )
- The literal form of a BLOB starts with X' ... and your CHARACTER value does not.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Apr 08, 2010 12:23 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

I guess the big question here is
what is InputRoot.XMLNS.NS1:SapGenericIDocObject.IDocStreamData defined as?
Is this defined as CHARACTER type or defined as BLOB type?, or even as 64 bit encoded?

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
radhika.tharayil
PostPosted: Thu Apr 08, 2010 9:46 pm    Post subject: Reply with quote

Newbie

Joined: 06 Apr 2010
Posts: 7

Hi,

I have not declared InputRoot.XMLNS.NS1:SapGenericIDocObject.IDocStreamData as either char or blob or base64encoded.

I am just declaring a refrence like

DECLARE InputXMLNSRef REFERENCE TO InputRoot.XMLNS.NS1:SapGenericIDocObject.IDocStreamData;

Actually the InputRoot.XMLNS.NS1:SapGenericIDocObject.IDocStreamData is of data type hexbinary in the defintion of SapGenericIDocObject.mxsd.

Th stream looks something like this

<NS1:SapGenericIDocObject xmlns:NS1="http://www.ibm.com/xmlns/prod/websphere/j2ca/sap/sapgenericidocobject">
<SAPTransactionID>995893A93B704BB349B93947</SAPTransactionID>
<IDocStreamData>4544495f44433430202031323530303030303030303030343932323935373031203330313220205348504d4e54303520202020202020202020202020202202020................... (I am not copying the entire stream)</IDocStreamData>
<IDocType>SHPMNT05</IDocType>
</NS1:SapGenericIDocObject>

Should I declare it as as character type and then try.
Back to top
View user's profile Send private message
kimbert
PostPosted: Fri Apr 09, 2010 12:15 am    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

I suggest that you
- switch to XMLNSC
- enable validation
- enable 'Build tree using XML Schema'.

The hexBinary element will appear in the message tree as a BLOB, and you don't have to write any ESQL.

I would have said this earlier, but I didn't realize that you were getting the string from an XML message.
Back to top
View user's profile Send private message
radhika.tharayil
PostPosted: Sat Apr 10, 2010 10:27 am    Post subject: Reply with quote

Newbie

Joined: 06 Apr 2010
Posts: 7

Hello All,

Thankyou so much for your help!!!

Indeed when i switched to XMLNSC parser, in validation mode the hex was converted to BLOB, and then when I casted this BLOB to Char using the InputRoot.Properties CCSID and Encoding it worked [/img]
Back to top
View user's profile Send private message
lancelotlinc
PostPosted: Tue Apr 13, 2010 9:48 am    Post subject: Reply with quote

Jedi Knight

Joined: 22 Mar 2010
Posts: 4941
Location: Bloomington, IL USA

Here is a nifty way to reference binary objects from JCN, in case you ever move to Java Compute Nodes in your flows.

Code:

String refCorrelId = new String();
   
for( int i = 0; i < 24; i++ ){
     
  String iHexStr = Integer.toHexString( msg.correlationId[i] );
  if ( iHexStr.length()>2 ) iHexStr = iHexStr.substring( iHexStr.length()-2 );
  if ( iHexStr.length()<2 ) refCorrelId = refCorrelId + "0";
  refCorrelId = refCorrelId + iHexStr;     
     
}
Back to top
View user's profile Send private message Send e-mail
sunny_30
PostPosted: Wed Aug 11, 2010 1:55 pm    Post subject: Reply with quote

Master

Joined: 03 Oct 2005
Posts: 258

HI,

Im having same problem. Its mentioned in this thread that the HEX data has to be parsed as XMLNSC to convert to BLOB, then later BLOB needs to be cast to CHaracter.

Shouldnt below ESQL convert the Hex to Blob in a more efficient manner:

Quote:
DECLARE ns NAMESPACE
'http://www.ibm.com/xmlns/prod/websphere/j2ca/sap/SapGenericIDocObject';
CREATE COMPUTE MODULE xxx_Compute
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
CALL CopyMessageHeaders();
set OutputRoot.BLOB.BLOB = InputRoot.DataObject.ns:SapGenericIDocObject.IDocStreamData;
RETURN TRUE;
END;


please let me know if there is a flaw using this code..
Thanks
Back to top
View user's profile Send private message
kimbert
PostPosted: Wed Aug 11, 2010 2:24 pm    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

Quote:
Its mentioned in this thread that the HEX data has to be parsed as XMLNSC to convert to BLOB,
Not exactly. Nobody has claimed that you *must* do it that way.
Quote:
Shouldnt below ESQL convert the Hex to Blob in a more efficient manner
Please explain
a) exactly how that code solves the problem ( I don't think it does )
and
b) why it is more efficient than any of the three solutions given above
Back to top
View user's profile Send private message
sunny_30
PostPosted: Sun Aug 15, 2010 4:34 pm    Post subject: Reply with quote

Master

Joined: 03 Oct 2005
Posts: 258

kimbert wrote:
a) exactly how that code solves the problem ( I don't think it does )

I used the same exact code and it has converted the data from HEX format:
eg: 4544495f44433430202031303030303030303030303....
to CHAR format flatfile-IDOC:
eg: EDI_DC40 1000000000069906007640...

kimbert wrote:
b) why it is more efficient than any of the three solutions given above

Not sure abt the efficiency part but what I meant was this approach is a much straightforward way to code in esql instead of using an extra XMLNS parser (RCD node?) etc
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Convert a hexbinary to a readable character
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.