ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Recursive Function

Post new topic  Reply to topic
 Recursive Function « View previous topic :: View next topic » 
Author Message
MB Developer
PostPosted: Thu Sep 25, 2014 2:35 am    Post subject: Recursive Function Reply with quote

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
View user's profile Send private message
smdavies99
PostPosted: Thu Sep 25, 2014 2:43 am    Post subject: Reply with quote

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
View user's profile Send private message
Esa
PostPosted: Thu Sep 25, 2014 3:04 am    Post subject: Re: Recursive Function Reply with quote

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
View user's profile Send private message
MB Developer
PostPosted: Thu Sep 25, 2014 3:25 am    Post subject: Reply with quote

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
View user's profile Send private message
Esa
PostPosted: Thu Sep 25, 2014 3:29 am    Post subject: Reply with quote

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
View user's profile Send private message
Esa
PostPosted: Thu Sep 25, 2014 3:32 am    Post subject: Reply with quote

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
View user's profile Send private message
MB Developer
PostPosted: Thu Sep 25, 2014 4:28 am    Post subject: Reply with quote

Disciple

Joined: 03 Feb 2014
Posts: 179

Hi ESA,

Yes I already changed to XMLNSC .
_________________
Thanks....
Back to top
View user's profile Send private message
MB Developer
PostPosted: Thu Sep 25, 2014 4:37 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Recursive Function
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.