cancel
Showing results for 
Search instead for 
Did you mean: 

Recursion in udf

vinaymittal
Contributor
0 Kudos

Hello,

I want to traverse a XML tree(or read all the XML nodes/count) i have the code with me  in regular java program format it uses recursion

public Static void main(String[] args)

{

     ThirdParser(node);

}

ThirdParser(node)

{

     visit(child)

}

visit(child)

{

     if condtn

          visit(child)

}

is it possible to write a class in a udf or a function and calling that function recursively.

PS: i know how to implement java mapping but want to explore if recursion is possible in udf or declaring a function inside a udf is possible.

Regards

Vinay

Accepted Solutions (1)

Accepted Solutions (1)

engswee
Active Contributor
0 Kudos

Hi Vinay

You can declare the recursive method under "Attributes and Method" section of MM as shown below.

You can then call the method from any UDF as shown below:-

As you can see, the recursive method is called five times as shown by the trace. You can ignore declaring and passing the container object in your method if you do not require any tracing, but it might be useful for debugging.

Caution: As it will be a recursive function, be careful to avoid an endless loop. You might want to code the function and test it locally in NWDS first prior to testing in the server.

Regards

Eng Swee

vinaymittal
Contributor
0 Kudos

Thanks Eng See

Answers (0)