Author |
Message
|
kirani |
Posted: Sun Nov 19, 2006 11:54 pm Post subject: PROCEDURES related problem |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
It's been long time since I visted this site, so first I'd like to say a BIG HELLO to everyone!
I am having problems with using PROCEDURES in WMB 6.0. I created few procedures in a differnet Message Flow project under a new Broker schema. I would be referring these procedures/functions in my other message flow projects . The objective here is to maintain common piece of code in one place. I have following procedures,
1. Copy Message Headers: This procedure is identical to standard CopyMessageHeaders procedure expect that I used DOMAIN clause to create proper parser before the Message Tree is copied. Here is the ESQL code.
Code: |
CREATE PROCEDURE CASS_CopyMessageHeaders(IN OutputRoot REFERENCE, IN InputRoot REFERENCE)
BEGIN
DECLARE I INTEGER;
DECLARE J INTEGER;
SET I = 1;
SET J = CARDINALITY(InputRoot.*[]);
WHILE I < J DO
CREATE LASTCHILD OF OutputRoot DOMAIN FIELDNAME (InputRoot.*[I]);
SET OutputRoot.*[I] = InputRoot.*[I];
SET I = I + 1;
END WHILE;
END;
|
2. Set Properties Folder: This procedure sets few
Code: |
CREATE PROCEDURE SetContractRplyProperties(IN OutputRoot REFERENCE)
BEGIN
SET OutputRoot.Properties.MessageSet = 'DR9HCKC0PM001';
SET OutputRoot.Properties.MessageFormat = 'XML';
END;
|
3. Copy Entire MRM: This procedures copies entire MRM.
Code: |
CREATE PROCEDURE CopyEntireMRM(IN OutputRoot REFERENCE, IN InputRoot REFERENCE)
BEGIN
CREATE LASTCHILD OF OutputRoot DOMAIN 'MRM';
SET OutputRoot.MRM = InputRoot.MRM;
END;
|
In my compute node, I am using following,
Code1 works ..
Code: |
CREATE FUNCTION main() RETURNS BOOLEAN
BEGIN
DECLARE I INTEGER;
DECLARE J INTEGER;
SET I = 1;
SET J = CARDINALITY(InputRoot.*[]);
WHILE I < J DO
SET OutputRoot.*[I] = InputRoot.*[I];
SET I = I + 1;
END WHILE;
-- Set Message Set Properties;
SET OutputRoot.Properties.MessageSet = 'DR9HCKC0PM001';
SET OutputRoot.Properties.MessageFormat = 'XML';
SET OutputRoot.Properties.MessageType = 'm_LAPCRTH0_RPLY';
SET OutputRoot."MRM" = InputRoot."MRM";
RETURN true;
END;
|
Code2 does not work ....
Code: |
CREATE FUNCTION main() RETURNS BOOLEAN
BEGIN
call Myschema.CASS_CopyMessageHeaders(OutputRoot,InputRoot);
-- Set Message Set Properties;
SET OutputRoot.Properties.MessageSet = 'DR9HCKC0PM001';
SET OutputRoot.Properties.MessageFormat = 'XML';
SET OutputRoot.Properties.MessageType = 'm_LAPCRTH0_RPLY';
SET OutputRoot."MRM" = InputRoot."MRM";
RETURN true;
END;
|
The problem with code2 is that it's complaining about having multiple "Properties" folder (BIP2120) in the output tree after this node. Any idea what else is missing in the Procedure here? Also, is the procedure setup correctly to setup Properties folder or do I need to change it? I've already looked at this forum for posts related to "PROCEDURES" in WMB 6.0 but could not find anything that would solve my problem. _________________ 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 |
|
 |
jefflowrey |
Posted: Mon Nov 20, 2006 2:26 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Yow! It has been a while, welcome back, man.
You generally need to pass a Reference to OutputRoot when you want to manipulate it in procedures that are outside the module scope. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Nov 20, 2006 3:23 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
jefflowrey wrote: |
Yow! It has been a while, welcome back, man.
You generally need to pass a Reference to OutputRoot when you want to manipulate it in procedures that are outside the module scope. |
In procedures AND functions outside of the module scope.
So if that function is outside the module scope you would need to pass it the OutputRoot as reference... Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Nov 20, 2006 4:36 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
I stopped caring whether something was a procedure or a function when I stopped writing FORTRAN. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
mgk |
Posted: Mon Nov 20, 2006 6:13 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Hi, Welcome back!
The problem here is not that you are not using references, you clearly are! The problem is that the OutputRoot Tree ALWAYS has a default (empty) Properties parser created for you before you enter the node. Therefore, when you call your "copy headers by reference" procedure, you end up creating ANOTHER properties parser under the OutputRoot tree. To solve this, assuming you only call your "copy headers by reference" procedure at the beginning of your node, is to use of of these versions of your procedure below:
Version 1: Delete the extra Properties folder before copying headers:
Code: |
CREATE PROCEDURE CASS_CopyMessageHeaders(IN OutputRoot REFERENCE, IN InputRoot REFERENCE)
BEGIN
DECLARE I INTEGER;
DECLARE J INTEGER;
SET I = 1;
SET J = CARDINALITY(InputRoot.*[]);
DELETE OutputRoot.Properties;
WHILE I < J DO
CREATE LASTCHILD OF OutputRoot DOMAIN FIELDNAME (InputRoot.*[I]);
SET OutputRoot.*[I] = InputRoot.*[I];
SET I = I + 1;
END WHILE;
END; |
Version 2: Reply on the fact Properties should always be the firstchild of root, copy it explictly, then just copy the rest of the headers starting after the properties folder (by setting I to start at 2):
Code: |
CREATE PROCEDURE CASS_CopyMessageHeaders(IN OutputRoot REFERENCE, IN InputRoot REFERENCE)
BEGIN
DECLARE I INTEGER;
DECLARE J INTEGER;
SET I = 2;
SET J = CARDINALITY(InputRoot.*[]);
SET OutputRoot.Properties = InputRoot.Properties;
WHILE I < J DO
CREATE LASTCHILD OF OutputRoot DOMAIN FIELDNAME (InputRoot.*[I]);
SET OutputRoot.*[I] = InputRoot.*[I];
SET I = I + 1;
END WHILE;
END; |
Note that I have not tested either of these code snippets .
I would generally favour version 2 myself though.
Note to jeff and fjb_saper: In V6 FUNCTIONS and PROCEDURES are now (almost) the same thing, so for most things you do not need to care which you use.
Regards, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
kirani |
Posted: Mon Nov 20, 2006 8:12 am Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
Thanks guys!
MGK - Let me test this thing out when I get to the office. I will pose the results later today. I hope there is no problem with my other procedures where I am manipulating the Properties folder.
And yes as MGK said, I am passing the REFERENCE to the OutputRoot in my code. _________________ 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 |
|
 |
fjb_saper |
Posted: Mon Nov 20, 2006 9:08 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
kirani wrote: |
Thanks guys!
MGK - Let me test this thing out when I get to the office. I will pose the results later today. I hope there is no problem with my other procedures where I am manipulating the Properties folder.
And yes as MGK said, I am passing the REFERENCE to the OutputRoot in my code. |
Your problem (2 properties folders) comes from the fact that by default you already have a properties folder on the outputroot.
If you pass in an outputroot where previously you did
Code: |
SET OutputRoot.Properties = NULL; |
it should work and give you no problem...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
kirani |
Posted: Mon Nov 20, 2006 2:08 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
MGK,
I tested version2 of your code and it's working fine!
fjb_saper,
I'm sure your change will also work! _________________ 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 |
|
 |
kirani |
Posted: Tue Nov 21, 2006 11:28 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
MGK,
Just wondering about the standard CopyMessageHeaders procedure generated by the toolkit in a compute node. Why is that we don't have to copy the properties folder explicitly or use the Domain clause when copying other folders? Is it because the procedure is still in the main() function? _________________ 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 |
|
 |
fjb_saper |
Posted: Wed Nov 22, 2006 5:34 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
kirani wrote: |
MGK,
Just wondering about the standard CopyMessageHeaders procedure generated by the toolkit in a compute node. Why is that we don't have to copy the properties folder explicitly or use the Domain clause when copying other folders? Is it because the procedure is still in the main() function? |
It is because the procedure is in MODULE scope... _________________ MQ & Broker admin |
|
Back to top |
|
 |
mgk |
Posted: Wed Nov 22, 2006 5:59 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
fjb_saper wrote: |
kirani wrote: |
MGK,
Just wondering about the standard CopyMessageHeaders procedure generated by the toolkit in a compute node. Why is that we don't have to copy the properties folder explicitly or use the Domain clause when copying other folders? Is it because the procedure is still in the main() function? |
It is because the procedure is in MODULE scope... |
Kind of. The real reason is that a REFERENCE to OutputRoot behaves differently to OutputRoot itself. At MODULE level OutputRoot is always in scope so you can use it directly in all MODULE level function / procedures. However, if you had a REFERENCE to OutputRoot at MODULE level you would still see this difference. See other posts by me for a fuller description of the differences.
Cheers, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
kirani |
Posted: Wed Nov 22, 2006 1:32 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
Got it! _________________ 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 |
|
 |
|