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 » Retrieving a number that is stored as an string from BLOB

Post new topic  Reply to topic Goto page 1, 2  Next
 Retrieving a number that is stored as an string from BLOB « View previous topic :: View next topic » 
Author Message
Herbert
PostPosted: Tue Dec 05, 2006 6:10 am    Post subject: Retrieving a number that is stored as an string from BLOB Reply with quote

Centurion

Joined: 05 Dec 2006
Posts: 146
Location: Leersum, The Netherlands

Hi,

Is it possible to cast a number that is stored as a string in a blob field to a integer result field? Below code is not working.

Code:
  DECLARE INPUT BLOB X'313233'; -- In reality it is a substring out of somewhere in InputRoot.BLOB.BLOB

  DECLARE RESULT INTEGER;

  SET RESULT = CAST(INPUT as INTEGER);


Using a CHAR field als work field, first BLOB to CHAR and then CHAR TO INTEGER, does also not work.

I have it working with below code, however, for performance reasons I want a better solution.

Code:
  DECLARE LINE_LEN LENGTH(INPUT);
  DECLARE LINE_IDX INTEGER 1;
  DECLARE LINE_CHR CHAR '';

  WHILE LINE_IDX <= LINE_LEN DO
         
    SET LINE_CHR = LINE_CHR ||
      CASE SUBSTRING(INPUT FROM LINE_IDX FOR 1)
        WHEN X'30' THEN '0'
        WHEN X'31' THEN '1'
        WHEN X'32' THEN '2'
        WHEN X'33' THEN '3'
        WHEN X'34' THEN '4'
        WHEN X'35' THEN '5'
        WHEN X'36' THEN '6'
        WHEN X'37' THEN '7'
        WHEN X'38' THEN '8'
        WHEN X'39' THEN '9'
      END;

    SET LINE_IDX = LINE_IDX + 1;

  END WHILE;
      
  SET RESULT = CAST(LINE_CHR AS INTEGER);


Broker version is 5

Kind Regards, Herbert
Back to top
View user's profile Send private message Visit poster's website
jefflowrey
PostPosted: Tue Dec 05, 2006 6:24 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Define "does not work".

Also, you probably need to specify an ENCODING on the Cast.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
Herbert
PostPosted: Tue Dec 05, 2006 7:02 am    Post subject: Reply with quote

Centurion

Joined: 05 Dec 2006
Posts: 146
Location: Leersum, The Netherlands

jefflowrey wrote:
Define "does not work"..

Currently I have the error "Error casting from %3 to %4" with as extra text "Unsuitable source length", however I believe I have seen also other ones like "Is not a number"

jefflowrey wrote:
Also, you probably need to specify an ENCODING on the Cast.

Interesting, I was thinking that when a message was retrieved by the broker from the queue it is always converted to unicode. Thanks for the tip.
Back to top
View user's profile Send private message Visit poster's website
jefflowrey
PostPosted: Tue Dec 05, 2006 7:15 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

If you're working with BLOB data, you need to instruct the broker what encoding to use to construct the integer values when trying to interpret the bits.

If you're working with CHARACTER data, then you may need to specify the CCSID as well.

If you're Modelling your data, then the message definition should handle this without problem.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
Herbert
PostPosted: Tue Dec 05, 2006 8:02 am    Post subject: Reply with quote

Centurion

Joined: 05 Dec 2006
Posts: 146
Location: Leersum, The Netherlands

jefflowrey wrote:
If you're Modelling your data, then the message definition should handle this without problem.

I decided to work in BLOB mode because I did not see a way to construct a MRM definition for it.

The input is N combinations of 2 fields. (there is no information about how big N is)
- first field is 8 bytes, its a number, left aligned, right padded with spaces
- second field is N bytes with the lenght of the first field.

Do you see a way to build a MRM for it?
Back to top
View user's profile Send private message Visit poster's website
jefflowrey
PostPosted: Tue Dec 05, 2006 8:14 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

I've forgotten if CWF will handle integers written as character data.

If it does, then you can model this as two fields in a CWF message, with the second field having a Length Reference equal to the first field.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
Herbert
PostPosted: Tue Dec 05, 2006 8:49 am    Post subject: Reply with quote

Centurion

Joined: 05 Dec 2006
Posts: 146
Location: Leersum, The Netherlands

jefflowrey wrote:
If it does, then you can model this as two fields in a CWF message, with the second field having a Length Reference equal to the first field.

Ok, but those 2 fields are together also a repeating group that occurs N times. However there is no information how many occurs there are. AFAIK MRM wants or a fixed occurs number or a reference to a other field.

A other quicky: Appending to the output in BLOB mode is that only possible with the below construction? Or is there a other solution that performs better?
Code:
SET OutputRoot.BLOB.BLOB = OutputRoot.BLOB.BLOB || MORE_DATA;
Back to top
View user's profile Send private message Visit poster's website
jefflowrey
PostPosted: Tue Dec 05, 2006 9:48 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Yeah, if you have an dynamic number of repeats, and you don't have delimited data, AND you have fields after the repeating structure, you can't model it in MRM. In fact, you might not be able to model it in anything....

The concatenation operation should perform relatively well.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
EddieA
PostPosted: Tue Dec 05, 2006 10:16 am    Post subject: Reply with quote

Jedi

Joined: 28 Jun 2001
Posts: 2453
Location: Los Angeles

Quote:
you might not be able to model it in anything

NEON

Cheers,
_________________
Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Tue Dec 05, 2006 10:46 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

EddieA -
I'm sure NEON can't distinguish between an undelimited repeating set of strings, and a set of string fields that follows after.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
EddieA
PostPosted: Tue Dec 05, 2006 11:08 am    Post subject: Reply with quote

Jedi

Joined: 28 Jun 2001
Posts: 2453
Location: Los Angeles

jefflowrey wrote:
EddieA -
I'm sure NEON can't distinguish between an undelimited repeating set of strings, and a set of string fields that follows after.

True, but the OP only has the unknown number of repeats. there is no mention of "other data" following.

Cheers,
_________________
Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Tue Dec 05, 2006 11:11 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

But the OP probably doesn't have NEON either...

And if there aren't fields following, then MRM can handle it - because of Repeat til End of Bitstream.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
Herbert
PostPosted: Tue Dec 05, 2006 2:53 pm    Post subject: Reply with quote

Centurion

Joined: 05 Dec 2006
Posts: 146
Location: Leersum, The Netherlands

jefflowrey wrote:
And if there aren't fields following, then MRM can handle it - because of Repeat til End of Bitstream.

hmm, I know the option "End of Bitstream" for Length Units of a string field. But I can not find "Repeat til End of Bitstream." as a option for repeating groups.
Back to top
View user's profile Send private message Visit poster's website
jefflowrey
PostPosted: Tue Dec 05, 2006 2:56 pm    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

An unbounded number of occurrences (Max Occurs = -1) is allowed if the element or group is the last child in its parent group, and the group is terminated by the end of the message bit stream. On writing, the writer outputs all occurrences in the message tree, if this number is less than Min Occurs then additional default values are written.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
Herbert
PostPosted: Tue Dec 05, 2006 9:22 pm    Post subject: Reply with quote

Centurion

Joined: 05 Dec 2006
Posts: 146
Location: Leersum, The Netherlands

jefflowrey wrote:
An unbounded number of occurrences (Max Occurs = -1) is allowed if the element or group is the last child in its parent group, and the group is terminated by the end of the message bit stream.

Ok, thanks for your help.

BTW, I have solved my original problem by first casting the BLOB to CHAR with a CCSID and then casting this CHAR to INTEGER. Directly casting from BLOB to INTEGER with the ENCODING option did not work (the same length error when casting without the ENCODING option)

It's working now, however I will test the switch from BLOB mode to MRM mode to see if it solves the performance issue. (processing a message that is 64 MB takes 40 minutes in the Broker)
Back to top
View user's profile Send private message Visit poster's website
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 » Retrieving a number that is stored as an string from BLOB
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.