|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Extra MRM Getting Populated in the message |
« View previous topic :: View next topic » |
Author |
Message
|
satyasheel15 |
Posted: Tue Apr 05, 2005 8:36 pm Post subject: Extra MRM Getting Populated in the message |
|
|
Voyager
Joined: 04 Mar 2003 Posts: 86
|
Question.
I have following scenario.
One Parent Flow
One Sub Flow part of Parent Flow
In the Parent Flow, I have one COMPUTE NODE (A) and where I am generating a tree with the following code:
CREATE COMPUTE MODULE "ITEM.MESSAGE.GENERATION.esql"
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
-- CALL CopyMessageHeaders();
-- CALL CopyEntireMessage();
-- Setting the Output Message Properties
SET OutputRoot.MQMD = InputRoot.MQMD;
--SET OutputRoot.MQMD.Format = 'MQSTR';
SET OutputRoot.Properties = InputRoot.Properties;
-- Declaration of CRLF
DECLARE CRLF CHAR CAST (X'0D0A' AS CHARACTER CCSID 819);
-- Intialising the PIBroker Message Count
SET Environment.Variables.PIBRecordCOUNT = 0;
-- Reading the Input Message as BLOB and converting to CHARACTER
DECLARE InputBuffer CHARACTER (CAST(InputRoot."BLOB"."BLOB" AS CHARACTER CCSID 819));
DECLARE MsgHEADER CHARACTER (LEFT(InputBuffer, (POSITION(CRLF IN InputBuffer) - 1)));
SET InputBuffer = RIGHT(InputBuffer, (LENGTH(InputBuffer) - LENGTH(MsgHEADER) - 2 ));
-- Generating the HEADER Message TREE
CREATE LASTCHILD OF OutputRoot DOMAIN 'MRM'
PARSE(MsgHEADER,InputRoot.Properties.Encoding,InputRoot.Properties.CodedCharSetId,
'GR5TSCG002001','m_HEADER','TDS1');
DECLARE MsgSUPPLIER CHARACTER (LEFT(InputBuffer, ((POSITION((CRLF || '2' || '|') IN InputBuffer)) - 1)));
SET InputBuffer = (RIGHT(InputBuffer, (LENGTH(InputBuffer) - (POSITION((CRLF || '3' || '|') IN InputBuffer) + 1))));
DECLARE MsgITEM CHARACTER (LEFT(InputBuffer, (POSITION((CRLF || '4' || '|') IN InputBuffer) - 1)));
SET InputBuffer = (RIGHT(InputBuffer, (LENGTH(InputBuffer) - (LENGTH(MsgITEM) + 2))));
-- Calling the function: fnApplyFilter to check following conditions:
-- Lines from Items (3) should not be mapped if:
-- the "EAN code" starts with 20 (if it starts with 20 it is an in-store EAN)
-- the "Date item status until" is not greater than the current system time.
-- the (Cocosoft) Brand ID in the Item line is included in the list of (Cocosoft) Brand IDs that need to
-- be skipped; the brand IDs that need to be skipped should be stored in the table CMERKF
-- " refer to Appendix A for a full list of Brand Names that should be skipped.
SET MsgITEM = fnApplyFilter(MsgITEM);
-- CREATING THE ITEM MESSAGE TREE
CREATE LASTCHILD OF OutputRoot DOMAIN 'MRM'
PARSE(MsgITEM,InputRoot.Properties.Encoding,InputRoot.Properties.CodedCharSetId,
'GR5TSCG002001','m_ITEMS','TDS1');
-- TAKING OUT THE END BLOCK FROM MESSAGE
DECLARE MsgEND CHARACTER SUBSTRING(InputBuffer FROM (POSITION((CRLF || '9' || '|') IN InputBuffer) + 2));
SET InputBuffer = (LEFT(InputBuffer, (LENGTH(InputBuffer) - (LENGTH(MsgEND) + 2 ))));
DECLARE MsgEAN CHARACTER InputBuffer;
-- CREATING THE EAN MESSAGE TREE
CREATE LASTCHILD OF OutputRoot DOMAIN 'MRM'
PARSE(MsgEAN,InputRoot.Properties.Encoding,InputRoot.Properties.CodedCharSetId,
'GR5TSCG002001','m_EAN_CODES','TDS1');
-- Generating the SUPPLIER Message TREE
CREATE LASTCHILD OF OutputRoot DOMAIN 'MRM'
PARSE(MsgSUPPLIER,InputRoot.Properties.Encoding,InputRoot.Properties.CodedCharSetId,
'GR5TSCG002001','m_SUPPLIER','TDS1');
-- Calling the PROCEDURE ProcCheckInputDataset() to check the Mandatory fields of Initial Set
CALL ProcCheckInputDataset();
RETURN TRUE;
END;
--*********************************************************************************************
-- Function Name : fnApplyFilter()
-- Purpose : Rules for Condition Check:-
-- Lines from Items (3) should not be mapped if:
-- the "EAN code" starts with 20 (if it starts with 20 it is an
-- in-store EAN) the "Date item status until" is not greater than the
-- current system time. the (Cocosoft) Brand ID in the Item line is
-- included in the list of (Cocosoft) Brand IDs that need to be skipped;
-- the brand IDs that need to be skipped should be stored in the table CMERKF
-- " refer to Appendix A for a full list of Brand Names that should be skipped.
-- Arguments : CHARACTER
-- Return Type : CHARACTER
--*********************************************************************************************
CREATE FUNCTION fnApplyFilter(ITEMdata CHARACTER) RETURNS CHARACTER
BEGIN
SET Environment.Variables.FilterBrandID[] = (SELECT T.CMERKID FROM Database.CMERKF AS T);
-- Declaration of Variables
DECLARE MsgITEM CHARACTER '';
DECLARE nextPos INTEGER;
DECLARE presentBuffer CHARACTER ITEMdata;
DECLARE CountItem INTEGER (CARDINALITY(Environment.Variables.FilterBrandID[]));
DECLARE ITEMline CHARACTER;
DECLARE flag BOOLEAN;
DECLARE i INTEGER;
DECLARE BrandID CHARACTER;
DECLARE CRLF CHARACTER (CAST (X'0D0A' AS CHARACTER CCSID 819));
DECLARE EANcode CHARACTER;
DECLARE strDate CHARACTER;
DECLARE DtItmStUntil DATE;
WHILE (LENGTH(presentBuffer) > 0) DO
SET flag = TRUE;
SET i = 1;
SET nextPos = POSITION((CRLF || '3' || '|') IN presentBuffer) ;
IF (nextPos = 0) THEN
-- Setting the item line record. This if block takes care of last item record of the input
SET ITEMline = presentBuffer;
ELSE
-- Setting the item line record.
SET ITEMline = LEFT(presentBuffer, nextPos + 1);
END IF;
-- Extracting the EANcode to be used in checking
SET EANcode = TRIM(SUBSTRING(ITEMline
FROM (POSITION('|' IN ITEMline REPEAT + 16 ) + 1)
FOR ((POSITION('|' IN ITEMline REPEAT + 17 )) -
(POSITION('|' IN ITEMline REPEAT + 16)) - (1))));
SET strDate = TRIM(SUBSTRING(ITEMline
FROM (POSITION('|' IN ITEMline REPEAT + 15 ) + 1)
FOR ((POSITION('|' IN ITEMline REPEAT + 16 )) -
(POSITION('|' IN ITEMline REPEAT + 15)) - (1))));
IF (TRIM(strDate) = '') THEN
SET DtItmStUntil = '';
ELSE
SET strDate = RIGHT( strDate, 4)
|| '-'
|| SUBSTRING( strDate FROM 3 FOR 2)
|| '-'
|| LEFT( strDate, 2) ;
SET DtItmStUntil = CAST(strDate AS DATE);
END IF;
-- Checking for the Date Item Status Until. If it is not greater than the current date then whole item
-- record is skipped
IF ((DtItmStUntil <= CURRENT_DATE) AND (strDate <> '' ))THEN
SET flag = FALSE;
-- Checking for the EANcode. If first two characters of EANcode are '20'
-- then the whole ITEMline is skipped
ELSEIF (LEFT(EANcode, 2) = '20') THEN
SET flag = FALSE;
ELSE
SET BrandID = TRIM(SUBSTRING(ITEMline
FROM (POSITION('|' IN ITEMline REPEAT + 5 ) + 1)
FOR ((POSITION('|' IN ITEMline REPEAT + 6 )) -
(POSITION('|' IN ITEMline REPEAT +5)) - (1))));
SET BrandID = CAST(TRIM(BrandID) AS INTEGER);
WHILE (i <= CountItem) DO
IF (CAST(BrandID AS INTEGER) =
CAST(Environment.Variables.FilterBrandID[i].CMERKID AS INTEGER)) THEN
SET flag = FALSE ;
END IF;
SET i = i+1;
END WHILE;
END IF;
IF (flag = TRUE) THEN
SET MsgITEM = MsgITEM || ITEMline;
END IF;
SET presentBuffer = RIGHT( presentBuffer, LENGTH (presentBuffer) - LENGTH(ITEMline));
END WHILE;
RETURN MsgITEM;
END;
--*********************************************************************************************
-- Procedure Name : ProcCheckInputDataset()
-- Purpose : Instead of checking in MRM about the presence of OPTIONAL/MANDATORY
-- fields, similar chech has been done through ESQL Code. Exception are
-- thrown back if the conditions does not match the specifications for
-- Mutation and Initial Messsage
-- Return Type : None
--*********************************************************************************************
CREATE PROCEDURE ProcCheckInputDataset()
BEGIN
IF (OutputRoot.MRM[1].e_TYPE_DATASET = '02') THEN
DECLARE iCnt INTEGER CARDINALITY(OutputRoot.MRM[2].e_ITEMS[]);
DECLARE jCnt INTEGER 1;
WHILE(jCnt <= iCnt) DO
IF (OutputRoot.MRM[2].e_ITEMS[jCnt].e_ITEM_DESC1 IS NULL) OR
(OutputRoot.MRM[2].e_ITEMS[jCnt].e_SUPPLIER_ID IS NULL) OR
(OutputRoot.MRM[2].e_ITEMS[jCnt].e_BRAND_ID IS NULL) OR
(OutputRoot.MRM[2].e_ITEMS[jCnt].e_BRAND_NAME IS NULL) OR
(OutputRoot.MRM[2].e_ITEMS[jCnt].e_LINE IS NULL) OR
(OutputRoot.MRM[2].e_ITEMS[jCnt].e_DATE_ENTRY_IN_DTBNK IS NULL) OR
(OutputRoot.MRM[2].e_ITEMS[jCnt].e_ORDER_NUMBER_SUPPLIER IS NULL)OR
(OutputRoot.MRM[2].e_ITEMS[jCnt].e_CONTENTS IS NULL) OR
(OutputRoot.MRM[2].e_ITEMS[jCnt].e_ITEM_STATUS IS NULL) OR
(OutputRoot.MRM[2].e_ITEMS[jCnt].e_DATE_ITM_STA_FROM IS NULL) OR
(OutputRoot.MRM[2].e_ITEMS[jCnt].e_DATE_ITM_STA_UNTIL IS NULL) OR
(OutputRoot.MRM[2].e_ITEMS[jCnt].e_EAN_CODE IS NULL) OR
(OutputRoot.MRM[2].e_ITEMS[jCnt].e_PURCHASE_PRICE IS NULL) OR
(OutputRoot.MRM[2].e_ITEMS[jCnt].e_RETAIL_PRICE IS NULL) OR
(OutputRoot.MRM[2].e_ITEMS[jCnt].e_VAT_CODE IS NULL) THEN
THROW USER EXCEPTION MESSAGE 2950 VALUES ('Mandatory Field Not Present');
END IF;
SET jCnt = jCnt + 1;
END WHILE;
END IF;
END;
In the Sub-Flow, I have another COMPUTE NODE (B) where my generating a multiple message using PROPAGATE. The input MRM is coming from the COMPUTE NODE (A) into COMPUTE NODE(B) where I am doing the transformation logic and generating multiple message using PROPAGATE.
CODE FOR COMPUTE NODE ( B):
CREATE COMPUTE MODULE "CCSLUXE.Cocosoft.To.IN.RETAIL.PRICE.DYNA.esql"
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
CALL CopyMessageHeaders();
-- Taking the Count of the ITEM Repeation from the Input Message
DECLARE iCnt INTEGER CARDINALITY(InputRoot.MRM[2].e_ITEMS[]);
DECLARE jCnt INTEGER 1;
-- Enviornment Variable -> Sequence Number will contain the count of the records
-- and initialised with the value '1'
SET Environment.Variables.SeqNum_RetailPrice = 1 ;
WHILE(jCnt <= iCnt) DO
--set OutputRoot.MRM = InputRoot.MRM;
SET OutputRoot.MRM = NULL ;
--CALL CopyMessageHeaders();
--SET OutputRoot.Properties.MessageDomain = 'MRM';
SET OutputRoot.Properties.MessageSet = 'HPJU0GS002001';
SET OutputRoot.Properties.MessageType = 'retailprices';
SET OutputRoot.Properties.MessageFormat = 'XML1';
DECLARE INRefToItems REFERENCE TO InputRoot.MRM[2];
--DECLARE OUTRefToRetailPrice REFERENCE TO OutputRoot.MRM.retailprice;
-- Transformation Rule : ADD
-- Insert (default) value ‘1’
SET OutputRoot.MRM.retailprice.pvfstat = '1';
-- Transformation Rule : COPY
SET OutputRoot.MRM.retailprice.pvfiddeb = InputRoot.MRM[2].e_ITEMS[jCnt].e_MUTATION_DATE ;
-- Transformation Rule : MODIFY
-- If Mutation code is 1 or 2 fill with (default) date - ‘2049/12/31’If Mutation code is 3,
-- fill with Mutation date
IF ((TRIM(InputRoot.MRM[2].e_ITEMS[jCnt].e_MUTATION_CODE) = '1') OR
(TRIM(INRefToItems.e_ITEMS[jCnt].e_MUTATION_CODE) = '2')) THEN
SET OutputRoot.MRM.retailprice.pvfidfin = '2049/12/31';
ELSEIF (INRefToItems.e_ITEMS[jCnt].e_MUTATION_CODE = 3) THEN
SET OutputRoot.MRM.retailprice.pvfidfin = INRefToItems.e_ITEMS[jCnt].e_MUTATION_DATE ;
ELSE
THROW USER EXCEPTION MESSAGE 2950 VALUES ('UNALLOWED VALUE OF MUTATION CODE');
END IF;
-- Transformation Rule : MODIFY
IF (LENGTH(TRIM(INRefToItems.e_ITEMS[jCnt].e_ITEM_NUMBER)) > THEN
THROW USER EXCEPTION MESSAGE 2950 VALUES ('Message length is greater than 8');
ELSE
SET OutputRoot.MRM.retailprice.pvfcexr =
REPLICATE('0', 8 - (LENGTH(TRIM(INRefToItems.e_ITEMS[jCnt].e_ITEM_NUMBER))))
|| TRIM(INRefToItems.e_ITEMS[jCnt].e_ITEM_NUMBER) ;
END IF;
-- Transformation Rule : MODIFY
-- Lookup the "DA’s Laag" publieksprijs from the CPUBLPRV table using the EAN-code, and copy to
-- PVFPRIX.If the EAN code cannot be found in the table CPUBLPRV, copy "Retail price" to PVFPRIX:
-- If "Retail price" is however < €0,10 then the "Purchase" price" should be multiplied by 2 and
-- copied to PVFPRIX.
DECLARE VARConsumerPrice CHARACTER THE(SELECT ITEM T.PUBLIEKSPRIJS FROM Database.CPUBLPRV AS T
WHERE T.EAN = INRefToItems.e_ITEMS[jCnt].e_EAN_CODE);
IF (VARConsumerPrice IS NOT NULL) THEN
SET OutputRoot.MRM.retailprice.pvfprix = VARConsumerPrice;
ELSEIF (CAST(INRefToItems.e_ITEMS[jCnt].e_RETAIL_PRICE AS FLOAT) < '0.1') THEN
SET OutputRoot.MRM.retailprice.pvfprix =
CAST(INRefToItems.e_ITEMS[jCnt].e_PURCHASE_PRICE AS FLOAT) * 2;
ELSE
SET OutputRoot.MRM.retailprice.pvfprix = INRefToItems.e_ITEMS[jCnt].e_RETAIL_PRICE;
END IF;
-- Transformation Rule : COPY
-- VAT code
-- (possible values:
-- 1 = no tax
-- 2 = low
-- 3 = high)
IF (CAST(INRefToItems.e_ITEMS[jCnt].e_VAT_CODE AS INTEGER) NOT IN (1, 2, 3)) THEN
THROW USER EXCEPTION MESSAGE 2950 VALUES ('UNALLOWED VALUE OF VAT CODE');
ELSE
SET OutputRoot.MRM.retailprice.pvfctva = CAST(INRefToItems.e_ITEMS[jCnt].e_VAT_CODE AS INTEGER);
END IF;
-- Transformation Rule : ADD
-- Sequence number for each record and start with 1
SET OutputRoot.MRM.retailprice.pvfnlig = Environment.Variables.SeqNum_RetailPrice ;
/**********************************************************************************
OUTPUT FIELD NOT PRESENT
**********************************************************************************/
-- IF ((THE(SELECT ITEM T.EAN FROM Database.CPUBLPRV AS T
-- WHERE T.EAN = INRefToItems.e_ITEMS[jCnt].e_EAN_CODE))IS NOT NULL) THEN
-- SET OutputRoot.MRM.retailprice.pvfprio = '20';
-- ELSE
-- SET OutputRoot.MRM.retailprice.pvfprio = '40';
-- END IF;
/**********************************************************************************
OUTPUT FIELD NOT PRESENT
**********************************************************************************/
-- Incrementing the Environment Variables to Point to next Record.
SET Environment.Variables.SeqNum_RetailPrice = Environment.Variables.SeqNum_RetailPrice + 1;
PROPAGATE ;
SET jCnt = jCnt + 1 ;
END WHILE;
RETURN FALSE;
END;
CREATE PROCEDURE CopyMessageHeaders() BEGIN
DECLARE I INTEGER 1;
DECLARE J INTEGER CARDINALITY(InputRoot.*[]);
WHILE I < J DO
SET OutputRoot.*[I] = InputRoot.*[I];
SET I = I + 1;
END WHILE;
END;
END MODULE;
But the problem is that after the output of COMPUTE NODE (B), I am still getting the MRM which is generated from COMPUTE NODE (A) along with MRM tree generated in COMPUTE NODE(B). I like to have the only those MRM tree which is generated in the COMPUTE NODE (B). Please explain where I am doing wrong in the code. |
|
Back to top |
|
 |
martinrydman |
Posted: Tue Apr 05, 2005 11:17 pm Post subject: |
|
|
 Centurion
Joined: 30 Jan 2004 Posts: 139 Location: Gothenburg, Sweden
|
Hi,
I think you need to cut down on the code you post here. Use the debugger to pinpoint the problem (and code) and if you're still unable to solve it, then post the part of the code you suspect is flawed. That would increase your chances of getting an answer.
/Martin |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|