Author |
Message
|
Herbert |
Posted: Tue Dec 05, 2006 6:10 am Post subject: Retrieving a number that is stored as an string from BLOB |
|
|
 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 |
|
 |
jefflowrey |
Posted: Tue Dec 05, 2006 6:24 am Post subject: |
|
|
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 |
|
 |
Herbert |
Posted: Tue Dec 05, 2006 7:02 am Post subject: |
|
|
 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 |
|
 |
jefflowrey |
Posted: Tue Dec 05, 2006 7:15 am Post subject: |
|
|
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 |
|
 |
Herbert |
Posted: Tue Dec 05, 2006 8:02 am Post subject: |
|
|
 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 |
|
 |
jefflowrey |
Posted: Tue Dec 05, 2006 8:14 am Post subject: |
|
|
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 |
|
 |
Herbert |
Posted: Tue Dec 05, 2006 8:49 am Post subject: |
|
|
 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 |
|
 |
jefflowrey |
Posted: Tue Dec 05, 2006 9:48 am Post subject: |
|
|
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 |
|
 |
EddieA |
Posted: Tue Dec 05, 2006 10:16 am Post subject: |
|
|
 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 |
|
 |
jefflowrey |
Posted: Tue Dec 05, 2006 10:46 am Post subject: |
|
|
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 |
|
 |
EddieA |
Posted: Tue Dec 05, 2006 11:08 am Post subject: |
|
|
 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 |
|
 |
jefflowrey |
Posted: Tue Dec 05, 2006 11:11 am Post subject: |
|
|
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 |
|
 |
Herbert |
Posted: Tue Dec 05, 2006 2:53 pm Post subject: |
|
|
 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 |
|
 |
jefflowrey |
Posted: Tue Dec 05, 2006 2:56 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
|
Back to top |
|
 |
Herbert |
Posted: Tue Dec 05, 2006 9:22 pm Post subject: |
|
|
 Centurion
Joined: 05 Dec 2006 Posts: 146 Location: Leersum, The Netherlands
|
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 |
|
 |
|