Posted: Tue Jun 28, 2005 12:35 pm Post subject: Parse a BLOB for 0d0a (CR/LR)
Acolyte
Joined: 07 Jun 2005 Posts: 52
I am trying to use a compute node to parse a BLOB and Propagate message bases on the parsing. I have a fixth width input(33) but '0d0a' is not consistantly in the same position. Does anyone see the obvious or have a better way of doing this?
----code---
CREATE COMPUTE MODULE difms_resp_SHOP_parser
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
CALL CopyMessageHeaders();
DECLARE record BLOB;
DECLARE reclength INTEGER;
DECLARE cursor INTEGER;
SET reclength = 35;
SET cursor = 0;
SET OutputLocalEnvironment.This.FirstRet = TRIM(SUBSTRINGInputRoot."BLOB"."BLOB" from 33 for 2));
SET record = TRIM(SUBSTRING(InputRoot."BLOB"."BLOB" FROM cursor FOR 33 ));
SET OutputRoot."BLOB"."BLOB" = record;
WHILE record <> '0d0a' DO
PROPAGATE;
CALL CopyMessageHeaders();
SET cursor = cursor + reclength ;
-- This OutputLocalEnvironment NEVER sits
SET OutputLocalEnvironment.This.SecRet = TRIM(SUBSTRING(InputRoot."BLOB"."BLOB" from 33 for 2));
--SET record = TRIM(SUBSTRING(InputRoot."BLOB"."BLOB" FROM cursor FOR 33 ));
SET record = '0d0a';
SET OutputRoot."BLOB"."BLOB" = record;
END WHILE;
CALL CopyMessageHeaders();
-- EOF 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' in HEX.
SET record = '585858585858585858585858585858585858585858585858585858585858585858';
SET OutputRoot."BLOB"."BLOB" = record;
SET CRLR = '0a';
SET reclength = 33;
SET cursor = 0;
SET ncursor = POSITION ( CRLR IN InputRoot."BLOB"."BLOB" from cursor) + 1;
SET BLOBLENGTH = LENGTH(InputRoot."BLOB"."BLOB");
SET record = TRIM(SUBSTRING(InputRoot."BLOB"."BLOB" FROM cursor FOR reclength ));
SET OutputRoot."BLOB"."BLOB" = record;
SET vreclength = (ncursor - cursor) - 1;
SET RTN = TRUE;
--verify each line size is correct
lsize: WHILE ncursor < BLOBLENGTH DO
IF vreclength <> 34 THEN
THROW USER EXCEPTION CATALOG 'LsizeException' MESSAGE 100 VALUES(
'Line Size Exception occurred during ', Environment.Variables.CURRENTNODE,'Message: <message>');
SET RTN = FALSE;
LEAVE lsize;
END IF;
SET cursor = POSITION ( CRLR IN InputRoot."BLOB"."BLOB" from cursor) + 1;
SET ncursor = POSITION ( CRLR IN InputRoot."BLOB"."BLOB" from cursor) + 1;
SET vreclength = ncursor - cursor;
END WHILE lsize;
SET cursor = 0;
-- First line of Defense
IF (RTN) THEN
WHILE cursor < BLOBLENGTH DO
-- Double Wrap Protection
IF RTN <> FALSE THEN
PROPAGATE;
END IF;
CALL CopyMessageHeaders();
SET cursor = POSITION ( CRLR IN InputRoot."BLOB"."BLOB" from cursor) + 1;
SET record = TRIM(SUBSTRING(InputRoot."BLOB"."BLOB" FROM cursor FOR 32 ));
SET OutputRoot."BLOB"."BLOB" = record;
END WHILE;
CALL CopyMessageHeaders();
--EOF 'XXXXXX' in HEX.
SET record = '585858585858';
SET OutputRoot."BLOB"."BLOB" = record;
END IF;
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