Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Answered

Recursive procedure with a type list as Parameter

Posted on by 467

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. 


Categories:
  • 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 467 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

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,558 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,645 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans