Author |
Message
|
MB Developer |
Posted: Thu Sep 25, 2014 2:35 am Post subject: Recursive Function |
|
|
 Disciple
Joined: 03 Feb 2014 Posts: 179
|
Hi All,
Greetings...
I just run Sample from Infocenter ....
http://www-01.ibm.com/support/knowledgecenter/SSKM8N_7.0.0/com.ibm.etools.mft.doc/ak04960_.htm
CREATE FUNCTION statement
ESQL example 2
MQInput Node --> Compute Node --> MQOutput Node
MQInput Node:
Queue Name: TEST.IN
Input Message Parsing --> Message Domain --> XMLNSC : For XML messages (namespace aware, validation, low memory use)
MQ Output Node --> TEST.OUT
Compute Node Code:
Code: |
CREATE COMPUTE MODULE Recursive_MsgFlow_Compute
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
CALL CopyMessageHeaders();
-- CALL CopyEntireMessage();
SET OutputRoot.MQMD = InputRoot.MQMD;
DECLARE answer CHARACTER;
SET answer = '';
CALL navigate(InputRoot.XMLNS, answer);
SET OutputRoot.XMLNS.Data.FieldNames = answer;
RETURN TRUE;
END;
CREATE PROCEDURE navigate (IN root REFERENCE, INOUT answer CHARACTER)
BEGIN
SET answer = answer || 'Reached Field... Type:'
|| CAST(FIELDTYPE(root) AS CHAR)||
': Name:' || FIELDNAME(root) || ': Value :' || root || ': ';
DECLARE cursor REFERENCE TO root;
MOVE cursor FIRSTCHILD;
IF LASTMOVE(cursor) THEN
SET answer = answer || 'Field has children... drilling down ';
ELSE
SET answer = answer || 'Listing siblings... ';
END IF;
WHILE LASTMOVE(cursor) DO
CALL navigate(cursor, answer);
MOVE cursor NEXTSIBLING;
END WHILE;
SET answer = answer || 'Finished siblings... Popping up ';
END;
CREATE PROCEDURE CopyMessageHeaders() BEGIN
DECLARE I INTEGER 1;
DECLARE J INTEGER;
SET J = CARDINALITY(InputRoot.*[]);
WHILE I < J DO
SET OutputRoot.*[I] = InputRoot.*[I];
SET I = I + 1;
END WHILE;
END;
CREATE PROCEDURE CopyEntireMessage() BEGIN
SET OutputRoot = InputRoot;
END;
END MODULE; |
---> After Deploying when I run the flow then output will come like
<Data/>
but not like given in Infocenter :
the procedure produces the following output, which has been manually formatted:
.......
My Input file is :
<Person>
<Name>John Smith</Name>
<Salary period='monthly' taxable='yes'>-1200</Salary>
</Person>
So please give the solution .... _________________ Thanks.... |
|
Back to top |
|
 |
smdavies99 |
Posted: Thu Sep 25, 2014 2:43 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
Why not run the flow with usertrace enabled and try to see where it goes wrong?
but I can see something wrong. Look at the Parser domain for the MQInput node and the Parser domain used in the code. _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
Esa |
Posted: Thu Sep 25, 2014 3:04 am Post subject: Re: Recursive Function |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
The same thing happens to me all the time.
Forgetting to set message domain for the MQ Input node.
By the way, the sample code has a little blemish. The person who wrote it obviously didn't understand how IN parameters work:
Code: |
CREATE PROCEDURE navigate (IN root REFERENCE, INOUT answer CHARACTER)
BEGIN
SET answer = answer || 'Reached Field... Type:'
|| CAST(FIELDTYPE(root) AS CHAR)||
': Name:' || FIELDNAME(root) || ': Value :' || root || ': ';
DECLARE cursor REFERENCE TO root;
MOVE cursor FIRSTCHILD;
IF LASTMOVE(cursor) THEN
|
This would be better:
Code: |
CREATE PROCEDURE navigate (IN cursor REFERENCE, INOUT answer CHARACTER)
BEGIN
SET answer = answer || 'Reached Field... Type:'
|| CAST(FIELDTYPE(root) AS CHAR)||
': Name:' || FIELDNAME(root) || ': Value :' || root || ': ';
MOVE cursor FIRSTCHILD;
IF LASTMOVE(cursor) THEN
|
|
|
Back to top |
|
 |
MB Developer |
Posted: Thu Sep 25, 2014 3:25 am Post subject: |
|
|
 Disciple
Joined: 03 Feb 2014 Posts: 179
|
Thanks both of you,
Yes Esa ,When I take your code then
Identifier "root" cannot be resolved.
this warning will come, So where I can declare root element. _________________ Thanks.... |
|
Back to top |
|
 |
Esa |
Posted: Thu Sep 25, 2014 3:29 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
Yes, sorry I didn't notice that.
You need to replace all instances of "root" in the procedure with "cursor". |
|
Back to top |
|
 |
Esa |
Posted: Thu Sep 25, 2014 3:32 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
Now I see that you in fact have set message domain correctly in MQ Input.
The problem is that the sample code is very old and uses XMLNS instead of XNMLNSC. Change the code, not the message domain. |
|
Back to top |
|
 |
MB Developer |
Posted: Thu Sep 25, 2014 4:28 am Post subject: |
|
|
 Disciple
Joined: 03 Feb 2014 Posts: 179
|
Hi ESA,
Yes I already changed to XMLNSC . _________________ Thanks.... |
|
Back to top |
|
 |
MB Developer |
Posted: Thu Sep 25, 2014 4:37 am Post subject: |
|
|
 Disciple
Joined: 03 Feb 2014 Posts: 179
|
Hi Esa and smdavies99 Thanks for Responding ...
Now My code is working
Code: |
CREATE COMPUTE MODULE Recursive_MsgFlow_Compute
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
-- CALL CopyMessageHeaders();
-- CALL CopyEntireMessage();
SET OutputRoot.MQMD = InputRoot.MQMD;
DECLARE answer CHARACTER;
SET answer = ' ';
CALL navigate(InputRoot.XMLNSC, answer);
SET OutputRoot.XMLNSC.Data.FieldNames = answer;
RETURN TRUE;
END;
CREATE PROCEDURE navigate (IN root REFERENCE, INOUT answer1 CHARACTER)
BEGIN
DECLARE filedType CHARACTER CAST(FIELDTYPE(root) AS CHAR);
DECLARE filedName CHARACTER FIELDNAME(root);
IF filedType IS NOT NULL and filedName IS NOT NULL THEN
SET answer1 = answer1 || 'Reached Field... Type:'
|| filedType||
': Name:' ||filedName ;
END IF;
IF FIELDVALUE(root) IS NOT NULL THEN
SET answer1 = answer1 || ': Value is :' || root || ': ';
END IF;
DECLARE cursor REFERENCE TO root;
MOVE cursor FIRSTCHILD;
IF LASTMOVE(cursor) THEN
SET answer1 = answer1 || 'Field has children... drilling down ';
ELSE
SET answer1 = answer1 || 'Listing siblings... ';
END IF;
WHILE LASTMOVE(cursor) DO
CALL navigate(cursor, answer1);
MOVE cursor NEXTSIBLING;
END WHILE;
SET answer1 = answer1 || 'Finished siblings... Popping up ';
END;
CREATE PROCEDURE CopyMessageHeaders() BEGIN
DECLARE I INTEGER 1;
DECLARE J INTEGER;
SET J = CARDINALITY(InputRoot.*[]);
WHILE I < J DO
SET OutputRoot.*[I] = InputRoot.*[I];
SET I = I + 1;
END WHILE;
END;
CREATE PROCEDURE CopyEntireMessage() BEGIN
SET OutputRoot = InputRoot;
END;
END MODULE; |
_________________ Thanks.... |
|
Back to top |
|
 |
|