Skip to main content

Notifications

Small and medium business | Business Central, N...
Answered

Recursive procedure with a type list as Parameter

(0) ShareShare
ReportReport
Posted on by 505

Hi, 

I started working with linear programming inside of BC and the procedure I created is a recursive procedure that receives an integer and a list as parameters. 

pastedimage1656676610064v1.png

Now the problem is the following. 
The Recursive procedure works with the integer and the values are stored at the specific stages of the recursive procedure, but the the list value is kept to whatever was last removed. 
Even when moving back to the beginning  of the first loop. the list is not returned to the initially list values.

It might be that AL does not cater for storing Lists in recursive procedures but I could find any documentation to confirm it. 


  • Verified answer
    Brad_P Profile Picture
    Brad_P 1,542 on at
    RE: Recursive procedure with a type list as Parameter

    Hi,

    "A List is a reference type, so assigning an instance of a list to another variable or passing as a method parameter by value (for example without var), creates a second variable that reads/writes the same list. It does not create a new list."

    docs.microsoft.com/.../list-data-type

  • Hein Kruger Profile Picture
    Hein Kruger 505 on at
    RE: Recursive procedure with a type list as Parameter

    Hi Brad,

    Yes, I set the first element in the list equal to origin and then I remove it from the list before passing it to the procedure again. this will continue until there is only one element left in the list where it will then return a decimal value.  

    I removed the var from the parameter and still got the same outcome.

  • Suggested answer
    Brad_P Profile Picture
    Brad_P 1,542 on at
    RE: Recursive procedure with a type list as Parameter

    Are you modifying the list within the procedure? You're passing the list as a reference (var), which will pass the same list reference for each recursive call.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans