Recursive Function

Does Navision provide for Recursive Functions? I need to perform a certain task again and again until a certain condition is met. Every time I call the functon it will return a value and this value will be the input parameter for the same function to be called again. Pari Somasundaram

Yes it does. Regards

I think Allan’s response is correct but I do not believe the example in the question describes a recursive routine. Textbook definition of Recursion: A programming method in which a program calls itself. I believe that what you describe “Every time I call a function it will return a value and this value will be the input parameter for the same function to be called again” is not recursion but just a simple loop. Dave Studebaker das@libertyforever.com Liberty Grove Software A Navision Services Partner

Navision C/AL is able to handle the true recursion, I tried it. To: David S. If the function is calling itself it is a recursion, what else? Jozef Kiss

One more notice: Be very carefull by programing the end of the recursion. If you miss the condition when exit the function, navision wil hang up and after a while it crashes on stack overflow …

If a function calls itself, it is a recursion (i.e.if Function A calls Function A). In the example as I understand it: Function A calls Function B Function A receives a value from Function B in return Function A uses that value to again call Function B. Function A is calling Function B, not itself. We do not know what Function B is doing. But the example does not demonstrate recursion. Dave Studebaker das@libertyforever.com Liberty Grove Software A Navision Services Partner

quote:


Originally posted by jkiss: One more notice: Be very carefull by programing the end of the recursion. If you miss the condition when exit the function, navision wil hang up and after a while it crashes on stack overflow …


Thanks. I have been thinking about the end of the recursion and what needs to be done. When the code detects an end, should it just call EXIT to leave the recursive function? An example would help. Davis S.: I think I did not explain the situation very well. But yes, I plan on calling function A from my code, the first time. Then within the code of function A, I plan to call function A (itself). Thanks again. Pari Soamsundaram.

Pari, That would be recursion. Thanks for clearing that up. Regarding Jozef’s warning about stack overflow, he is right, that is the result of too many recursions (I have experienced this myself by accidentally creating a recursive call). While Navision can do recursion, you might be able to avoid any danger of stack overflow by designing your function so it worked like my A calling B example. Less elegant perhaps, but simpler (which is real important to simple folks like me). Dave Studebaker das@libertyforever.com Liberty Grove Software A Navision Services Partner

Keeping things simple is important but, on rare occations, Recursion is the only good solution. For example, if you want to explode a BOM with and unlimited number of levels, Recursion is the best (if not only) method. Bill Benefiel Manager of Information Systems Overhead Door Company billb@ohdindy.com (317) 842-7444 ext 117

quote:


Originally posted by wbenefiel: Keeping things simple is important but, on rare occations, Recursion is the only good solution. For example, if you want to explode a BOM with and unlimited number of levels, Recursion is the best (if not only) method. Bill Benefiel Manager of Information Systems Overhead Door Company billb@ohdindy.com (317) 842-7444 ext 117


Thanks Bill. You just confirmed that I’m on the right track. I’m in fact exploding a BOM. Pari Somasundaram.

Codeunit 54 uses some recursion. Regards