Author |
Message
|
radhika.tharayil |
Posted: Wed Apr 07, 2010 7:14 am Post subject: Convert a hexbinary to a readable character |
|
|
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 |
|
 |
Vitor |
Posted: Wed Apr 07, 2010 10:27 am Post subject: Re: Convert a hexbinary to a readable character |
|
|
 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 |
|
 |
kimbert |
Posted: Wed Apr 07, 2010 10:47 am Post subject: |
|
|
 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 |
|
 |
radhika.tharayil |
Posted: Thu Apr 08, 2010 9:22 am Post subject: |
|
|
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 |
|
 |
Vitor |
Posted: Thu Apr 08, 2010 9:25 am Post subject: |
|
|
 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 |
|
 |
radhika.tharayil |
Posted: Thu Apr 08, 2010 9:39 am Post subject: |
|
|
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 |
|
 |
kimbert |
Posted: Thu Apr 08, 2010 11:32 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Apr 08, 2010 12:23 pm Post subject: |
|
|
 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 |
|
 |
radhika.tharayil |
Posted: Thu Apr 08, 2010 9:46 pm Post subject: |
|
|
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 |
|
 |
kimbert |
Posted: Fri Apr 09, 2010 12:15 am Post subject: |
|
|
 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 |
|
 |
radhika.tharayil |
Posted: Sat Apr 10, 2010 10:27 am Post subject: |
|
|
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 |
|
 |
lancelotlinc |
Posted: Tue Apr 13, 2010 9:48 am Post subject: |
|
|
 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 |
|
 |
sunny_30 |
Posted: Wed Aug 11, 2010 1:55 pm Post subject: |
|
|
 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 |
|
 |
kimbert |
Posted: Wed Aug 11, 2010 2:24 pm Post subject: |
|
|
 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 |
|
 |
sunny_30 |
Posted: Sun Aug 15, 2010 4:34 pm Post subject: |
|
|
 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 |
|
 |
|