Author |
Message
|
Dale Atchley |
Posted: Thu Jun 28, 2001 10:18 am Post subject: |
|
|
Newbie
Joined: 27 Jun 2001 Posts: 4
|
I am attempting to pick up a 2 Character field in an incoming message. I need to convert the binary field to an integer. If I use BITSTREAM(InputRoot.MRM.field), It returns a string X'HHHH'. How can I convert that to an integer of the proper arithmetic value. HELP??? |
|
Back to top |
|
 |
EddieA |
Posted: Fri Jun 29, 2001 9:46 am Post subject: |
|
|
 Jedi
Joined: 28 Jun 2001 Posts: 2453 Location: Los Angeles
|
Can you define the field correctly in the MRM as a binary integer.
_________________ Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
Dale Atchley |
Posted: Fri Jun 29, 2001 11:38 am Post subject: |
|
|
Newbie
Joined: 27 Jun 2001 Posts: 4
|
Thanks for the reply. The problem is in the input MRM if you define an integer, it expects 4 bytes. I can bring it in as 2 bytes characer and then set a variable of type BLOB to BITSTREAM(InputRoot.MRM.2_Byte_Char) no problem. This appears to establish the BLOB variable with the notation X'hhhh'. From reading the ESQL reference now available on the IBM Site, there appears to be no way to work with this notation. You can neither CAST the BLOB as integer nor can you set it equal to an integer. IF you set it equal to a Variable of decimal type, it sets it to HHHH and interprets the hex digits as decimal digits. I have found no vehicle to deal with a BLOB as a numeric value. Thanks for your interest and help. |
|
Back to top |
|
 |
kolban |
Posted: Sat Jun 30, 2001 7:57 pm Post subject: |
|
|
 Grand Master
Joined: 22 May 2001 Posts: 1072 Location: Fort Worth, TX, USA
|
You could always use the NEON parser and define a NEON input format that maps to the bytes you wish parsed as integer. |
|
Back to top |
|
 |
Dale Atchley |
Posted: Mon Jul 02, 2001 6:46 am Post subject: |
|
|
Newbie
Joined: 27 Jun 2001 Posts: 4
|
Thanks, Neil. The following code works but I will investigate the NEON parser. Thanks for the tip:
DECLARE VARIABLES **********************************************
DECLARE BIN_IN_BLOB BLOB;
DECLARE BLOB_STRING CHAR;
DECLARE HEX_STRING CHAR;
DECLARE HEX_EXP_MULT INTEGER;
DECLARE HEX_DIG_MULT INTEGER;
DECLARE HEX_DIGIT INTEGER;
DECLARE HEX_LENGTH INTEGER;
DECLARE HEX_SUM INTEGER;
DECLARE HEX_CHAR CHAR;
DECLARE DEC_QUOTIENT DECIMAL;
DECLARE INT_QUOTIENT INTEGER;
--********************** SET BINARY INPUT **********
SET BIN_IN_BLOB = BITSTREAM(InputRoot.MRM.SB_VALUE);
SET BLOB_STRING = CAST(BIN_IN_BLOB AS CHAR);
-- *********************** NOW HAVE STRING OF FORM X'hhhh' *********************
-- *********************** CONVERT TO VALID INTEGER ***************************
-- ***** REMOVE X'....' FROM STRING **********************************
SET HEX_STRING = SUBSTRING(BLOB_STRING FROM 3 FOR 4);
SET HEX_LENGTH = LENGTH(HEX_STRING);
SET I = 1;
SET HEX_SUM = 0;
WHILE I <= HEX_LENGTH DO
SET HEX_EXP_MULT = CASE(I)
WHEN 1 THEN 4096
WHEN 2 THEN 256
WHEN 3 THEN 16
WHEN 4 THEN 1
END;
SET HEX_CHAR = SUBSTRING(HEX_STRING FROM I FOR 1);
SET HEX_DIGIT = CASE HEX_CHAR
WHEN '0' THEN 0
WHEN '1' THEN 1
WHEN '2' THEN 2
WHEN '3' THEN 3
WHEN '4' THEN 4
WHEN '5' THEN 5
WHEN '6' THEN 6
WHEN '7' THEN 7
WHEN '8' THEN 8
WHEN '9' THEN 9
WHEN 'A' THEN 10
WHEN 'B' THEN 11
WHEN 'C' THEN 12
WHEN 'D' THEN 13
WHEN 'E' THEN 14
WHEN 'F' THEN 15
END;
SET HEX_SUM = HEX_SUM + (HEX_EXP_MULT * HEX_DIGIT);
SET I = I + 1;
END WHILE;
--********************** INITIALIZE FLAG ARRAY ***********************************************************
SET I = 1;
WHILE I <= 16 DO
SET OutputRoot.MRM.FLAG_VALUE[I] = ' ';
SET I = I+1;
END WHILE;
--********************** DIVIDE BY TWO LOOP ***********************************************************SET I = 1;
SET I = 1;
SET DEC_QUOTIENT = HEX_SUM;
While I <=16 DO
SET DEC_QUOTIENT = DEC_QUOTIENT / 2;
SET INT_QUOTIENT = CAST(DEC_QUOTIENT AS INTEGER);
IF DEC_QUOTIENT = INT_QUOTIENT THEN
SET OutputRoot.MRM.FLAG_VALUE[17-I] = 'N';
ELSE
SET OutputRoot.MRM.FLAG_VALUE[17-I] = 'Y';
END IF;
SET DEC_QUOTIENT = CAST(DEC_QUOTIENT AS INTEGER);
SET I = I+1;
End While; |
|
Back to top |
|
 |
|