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 » Casting of BLOB to INTEGER

Post new topic  Reply to topic
 Casting of BLOB to INTEGER « View previous topic :: View next topic » 
Author Message
angka
PostPosted: Mon Sep 25, 2006 1:01 am    Post subject: Casting of BLOB to INTEGER Reply with quote

Chevalier

Joined: 20 Sep 2005
Posts: 406

Hi all,

I am trying to cast Blob to integer but some how it cannot be CAST below are my codes. Thanks

SET LEAD_ZEROS = X'00000000';
SET TEST_BLOB = SUBSTRING(InputRoot.MQMD.CorrelId FROM 1 FOR 4);
SET TEMP_BLOB = TEST_BLOB || LEAD_ZEROS;
SET TEST_INT = CAST(TEMP_BLOB AS INTEGER);

I am working on Windows platform so it is little Endian. When i step through the debug, the TEST_INT is not assign any value. Are there any mistakes from my codes? I did get this working in Broker V2.1 before. i am currently using V6. Thanks.
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Mon Sep 25, 2006 1:45 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

I don't think you can make any guarantees that an MQMD Correlation ID is going to start with four integer bytes. And you shouldn't be misusing this field to hold business data.

You could consider adding an ENCODING parameter to the CAST, though. It might help.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
angka
PostPosted: Mon Sep 25, 2006 2:00 am    Post subject: Reply with quote

Chevalier

Joined: 20 Sep 2005
Posts: 406

Hi,

The existing system is using this field so I can't change anything. I taking the first 4 bytes because it is in the business logic. I did set ENCODING InputRoot.Properties.Encoding before but it gave me the same result =(

Thanks =)
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Mon Sep 25, 2006 2:47 am    Post subject: Reply with quote

Grand High Poobah

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

Try passing the resulting BLOB to a java function that uses Integer.decode....
this way you can use "0x" + BLOB for the decode part.

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
mgk
PostPosted: Mon Sep 25, 2006 3:43 am    Post subject: Reply with quote

Padawan

Joined: 31 Jul 2003
Posts: 1642

I agree with Jeff that this is a bad idea in general. However, it should work. Can you post as example Input CorrelID and the rest of the ESQL showing the DECLAREs of the variables you are using. Also, if you could post a Usertrace showing this operation that would help too.


Regards,
_________________
MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions.
Back to top
View user's profile Send private message
angka
PostPosted: Mon Sep 25, 2006 6:45 pm    Post subject: Reply with quote

Chevalier

Joined: 20 Sep 2005
Posts: 406

Hi all,


I am working on Wintel platform. I have this subjectID of numeric value 111111111 which is coming in from an external system in hexa format. On my end, I need to cast this incoming hexa value into an integer to do processing. 111111111 is basically represented by hexa 069F6BC7. I did the following in my ESQL codes:

DECLARE SUBJ_ID INTEGER;

SET SUBJ_ID = CAST(X'00000000069F6BC7' AS INTEGER);

This works. However, I am puzzled by why it works. Specifically, I am working on a Wintel machine. Thus, I am expecting all representations to be in Little Endian format. However, the above representation is clearly in Big Endian. Have I missed out something?

Also, when I experimented with the following:

SET SUBJ_ID = CAST(X'00000000FFFFFFFF');

There is no results returned. It seems like although the INTEGER type is of 8 Bytes (64 bits), I can go beyond the least significant 4-Bytes.
Back to top
View user's profile Send private message
angka
PostPosted: Mon Sep 25, 2006 7:37 pm    Post subject: Reply with quote

Chevalier

Joined: 20 Sep 2005
Posts: 406

Hi,

Sorry, I understand that CAST function will cast all in Big Endian format.

But still can't figure out why INTEGER type is of 8 Bytes (64 bits), I cant go beyond 31 bits when casting. Thanks
Back to top
View user's profile Send private message
angka
PostPosted: Sun Oct 29, 2006 7:37 pm    Post subject: Reply with quote

Chevalier

Joined: 20 Sep 2005
Posts: 406

Hi,

I still cant figure out wat wrong with the CAST function.. Below are my codes.

DECLARE LEAD_ZEROS BLOB;
DECLARE FIRST_BYTE BLOB;
DECLARE SECOND_BYTE BLOB;
DECLARE THIRD_BYTE BLOB;
DECLARE FOURTH_BYTE BLOB;
DECLARE REQ_NO_BLOB BLOB;
DECLARE REQ_NO INTEGER;

SET LEAD_ZEROS = X'00000000';
SET REQ_NO_BLOB = X'FFFFFF7F';
SET FIRST_BYTE = SUBSTRING(REQ_NO_BLOB FROM 1 FOR 1);
SET SECOND_BYTE = SUBSTRING(REQ_NO_BLOB FROM 2 FOR 1);
SET THIRD_BYTE = SUBSTRING(REQ_NO_BLOB FROM 3 FOR 1);
SET FOURTH_BYTE = SUBSTRING(REQ_NO_BLOB FROM 4 FOR 1);
SET REQ_NO = CAST(LEAD_ZEROS || FOURTH_BYTE || THIRD_BYTE || SECOND_BYTE || FIRST_BYTE AS INTEGER);

X'FFFFFF7F' is the biggest value it can be casted. X'00000080' will give a blank value from the debug mode? Why is this so? or should i add ENCODING clause? i tried with MQENC_INTEGER_NORMAL AND MQENC_INTEGER_REVERSED it still the same. Thanks..
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Mon Oct 30, 2006 3:11 pm    Post subject: Reply with quote

Grand High Poobah

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

I think you need to understand far more than you'd like to solve this.

Depending on the platform and the size of the integer on the platform you will use X many bytes per integer. (64 bit processors typically allow for bigger values...).

Depending on the platform again the values may be reversed (little endian / big endian).

Depending on whether the system considers a signed integer or not the value will be different in decimal (max = 7FFF, 8000 would be the min negative value in case of a 2 byte signed integer).

And of course your parsing has to take all this into account...

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
jefflowrey
PostPosted: Mon Oct 30, 2006 3:39 pm    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Also, you may only get 64 bit numbers inside a 64bit execution group.

At least in terms of extracting 64 bits worth of BLOB data.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
angka
PostPosted: Mon Oct 30, 2006 6:02 pm    Post subject: Reply with quote

Chevalier

Joined: 20 Sep 2005
Posts: 406

Hi all,

Thanks for the clarification. So now I understand why. I am on a 32 bit processor and most likely a 2 complement platform.

Cheers
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 » Casting of BLOB to INTEGER
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.