Posted: Tue Dec 02, 2014 6:46 am Post subject: ASCII to EBDIC for IMS
Newbie
Joined: 02 Dec 2014 Posts: 1
CREATE PROCEDURE CopyEntireMessage() BEGIN
-- Using copyMessageHeaders to copying all the headers instead of InputRoot
-- SET OutputRoot = InputRoot;
DECLARE MSGLEN CHARACTER;
DECLARE NUMBER INTEGER;
DECLARE NUM INTEGER;
DECLARE RESULT INTEGER;
DECLARE REM INTEGER;
-- Set MSGLEN to non NULL to avoid errors when concatenating the first time
SET MSGLEN = 'X';
SET inputMessage = CAST ("InputRoot"."BLOB"."BLOB" AS CHARACTER CCSID 437);
SET inputMessageWithTxCode = 'FXMC RECV' || inputMessage;
SET outputMessage = CAST (inputMessageWithTxCode AS BLOB CCSID 500);
SET NUM = LENGTH(inputMessageWithTxCode);
SET NUMBER = NUM + 6;
--
-- Convert NUMBER to hexadecimal. The remainder of dividing by 16 is calculated recursively.
--
WHILE NUMBER > 15 DO SET RESULT = NUMBER/16;
SET REM = NUMBER - RESULT*16;
SET MSGLEN =
CASE
WHEN REM < 10 THEN CAST(REM AS CHARACTER) || MSGLEN
WHEN REM = 10 THEN 'A' || MSGLEN
WHEN REM = 11 THEN 'B' || MSGLEN
WHEN REM = 12 THEN 'C' || MSGLEN
WHEN REM = 13 THEN 'D' || MSGLEN
WHEN REM = 14 THEN 'E' || MSGLEN
ELSE 'F' || MSGLEN
END;
SET NUMBER = RESULT;
END WHILE;
SET REM = NUMBER;
SET MSGLEN =
CASE
WHEN REM < 10 THEN CAST(REM AS CHARACTER) || MSGLEN
WHEN REM = 10 THEN 'A' || MSGLEN
WHEN REM = 11 THEN 'B' || MSGLEN
WHEN REM = 12 THEN 'C' || MSGLEN
WHEN REM = 13 THEN 'D' || MSGLEN
WHEN REM = 14 THEN 'E' || MSGLEN
ELSE 'F' || MSGLEN
END;
--
-- Add leading zeros up to a length of 9 to be able to cast as BLOB.
-- Remember it started with MSGLEN set to X (length 1)
--SET MSGLEN = '1F';
WHILE LENGTH(MSGLEN) < 5 DO
SET MSGLEN = '0' || MSGLEN;
END WHILE;
--
-- Change to appropriate endian (PLATFORM DEPENDANT)
-- If no endian swapping needed then remember to get rid of the last character as below --
DECLARE MSGLEN1 CHARACTER;
SET MSGLEN1 = SUBSTRING(MSGLEN FROM 1 FOR 4);
DECLARE LLZZ CHARACTER;
SET LLZZ = MSGLEN1 || '0000';
DECLARE trailer CHARACTER;
SET trailer = 'FEFF';
SET "OutputRoot"."BLOB"."BLOB" = CAST(LLZZ AS BLOB) || outputMessage || CAST(trailer AS BLOB);
this is code for converting data from ascii to ebdic for ims. i have been finding answers for two questions for a while now.
1. why is num set number+6, i see num is also set to number+12 somewer else
2. why is msglen concatenated with 0000 to form llzz bytes
I am sure you can find a way in ESQL to avoid manually generating hexadecimal characters...! _________________ Well, I don't think there is any question about it. It can only be attributable to human error. This sort of thing has cropped up before, and it has always been due to human error.
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