Author |
Message
|
TonyD |
Posted: Mon Dec 06, 2004 4:55 pm Post subject: Converting String to Integer question |
|
|
Knight
Joined: 15 May 2001 Posts: 540 Location: New Zealand
|
I have an MRM message that contains a repeating group preceded by a Count field. All data is string, eg:
Code: |
Count 03
Group1 123
Group2 456
Group3 789
|
The message therefore looks like:
or:
Code: |
X'3033313233343536373839'
|
I need to convert the 2-byte Count to integer so that the MRM can resolve the number of occurences using this field.
The required result is therefore:
Code: |
X'0003313233343536373839'
|
If the Count was 55 the first two bytes would be X'0037'.
I have been able to achieve this. However the result is platform dependent. I am developing and testing in a Windows environment for deployment on a Unix machine. The 2-byte Windows representation of integer 3 is X'0300' vs X'0003' in Unix.
Is there a way that I can achieve the required result that is platform independent? That is, the integer is correctly represented depending upon the platform it is running on without having to change the ESQL. Also does anyone has an elegant way of converting the 2-byte string Count to a two-byte integer Count ? |
|
Back to top |
|
 |
EddieA |
Posted: Mon Dec 06, 2004 5:21 pm Post subject: |
|
|
 Jedi
Joined: 28 Jun 2001 Posts: 2453 Location: Los Angeles
|
Maybe I'm missing something, but don't you just declare the count in the MRM as an Integer, and cast the String to it. And as long as the Encoding is set to Native, it will be written out correctly for any platform.
Cheers, _________________ Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
TonyD |
Posted: Mon Dec 06, 2004 6:43 pm Post subject: |
|
|
Knight
Joined: 15 May 2001 Posts: 540 Location: New Zealand
|
Well it is probably me who is missing something but I'm always ready to be corrected....
In the actual situation I am working on the physical data that arrives at the MQInput node in my message for the 2-byte Count field is X'3033''. Although I have altered the MRM field definition, built from an imported Cobol copybook, from 'string' with length 2 to 'int' with length 2 this does not alter the fact that the data is not a valid integer representation. MRM parsing fails with an incorrect message length.
I therefore am reading the message as a BLOB, recalculating the value of Count to X'0003', and then converting it to little-endian X'0300' for my Intel environment. The message is then reparsed correctly through an RCD node.
The problem is that X'0300' will not be correct when the flow runs in a big-endian Unix environment.
Am I making things more difficult than they need to be?! |
|
Back to top |
|
 |
EddieA |
Posted: Mon Dec 06, 2004 11:44 pm Post subject: |
|
|
 Jedi
Joined: 28 Jun 2001 Posts: 2453 Location: Los Angeles
|
Quote: |
Am I making things more difficult than they need to be |
Maybe.
Quote: |
Although I have altered the MRM field definition, built from an imported Cobol copybook, from 'string' with length 2 to 'int' with length 2 |
Not quite. You need to change it so it's declared as an Extended Decimal. (I think that's the correct term). It's the equivalent of a COBOL PIC 99 field. This is a numeric field, but still as characters, not binary or packed decimal. Or, change the COBOL copybook from PIC XX to PIC 99 and re-import.
Cheers, _________________ Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
kirani |
Posted: Mon Dec 06, 2004 11:53 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
It does not matter in this case whether the field is defined as PIC 99. or PIC XX. The output will look same in either case. It would not work if the fields are defined as signed. _________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
EddieA |
Posted: Tue Dec 07, 2004 12:02 pm Post subject: |
|
|
 Jedi
Joined: 28 Jun 2001 Posts: 2453 Location: Los Angeles
|
Quote: |
It does not matter in this case whether the field is defined as PIC 99. or PIC XX |
But this is an Input field, used to determine how many repeats there are. I this case, I would have thought that it did matter.
Cheers, _________________ Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
TonyD |
Posted: Tue Dec 07, 2004 2:09 pm Post subject: |
|
|
Knight
Joined: 15 May 2001 Posts: 540 Location: New Zealand
|
Quote: |
But this is an Input field, used to determine how many repeats there are. I this case, I would have thought that it did matter
|
....it does matter because the MRM parser will only correctly calculate the number of occurrences if the Count (Repeat Reference) is an integer....in fact you cannot specify a field as a repeat reference unless it is defined as integer.
If the program that created the message had created the field as packed decimal there would be no problem but it didn't and it is not possible to change it to do so as it is used by a number of other functions.
If I have to modify my ESQL to decide the 'endian-ness' of the runtime enviroment what would be the best way to do this? |
|
Back to top |
|
 |
TonyD |
Posted: Tue Dec 07, 2004 2:55 pm Post subject: |
|
|
Knight
Joined: 15 May 2001 Posts: 540 Location: New Zealand
|
Quote: |
If I have to modify my ESQL to decide the 'endian-ness' of the runtime enviroment what would be the best way to do this?
|
...decided to test MQENC_NATIVE for '273' or '546' since these are the only two platforms involved...works OK. |
|
Back to top |
|
 |
TonyD |
Posted: Tue Dec 07, 2004 4:44 pm Post subject: |
|
|
Knight
Joined: 15 May 2001 Posts: 540 Location: New Zealand
|
Quote: |
You need to change it so it's declared as an Extended Decimal. (I think that's the correct term). It's the equivalent of a COBOL PIC 99 field. This is a numeric field, but still as characters, not binary or packed decimal. Or, change the COBOL copybook from PIC XX to PIC 99 and re-import.
|
...you were right EddieA!...and I was making things way more difficult than they needed to be!!
For some reason I had the idea firmly in my mind that the Count field had to be a binary integer....completely wrong! 'xsd:short' works perfectly well and makes all the stuff I wrote above completely unnecessary and also incorrect...please disregard! |
|
Back to top |
|
 |
EddieA |
Posted: Tue Dec 07, 2004 5:26 pm Post subject: |
|
|
 Jedi
Joined: 28 Jun 2001 Posts: 2453 Location: Los Angeles
|
Glad you got it working.
Cheers, _________________ Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
kirani |
Posted: Tue Dec 07, 2004 11:54 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
EddieA wrote: |
But this is an Input field, used to determine how many repeats there are. |
I missed this part  _________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
|