web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Recursive procedure with a type list as Parameter

(0) ShareShare
ReportReport
Posted on by 629

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. 


I have the same question (0)
  • Suggested answer
    Brad_P Profile Picture
    1,549 on at

    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.

  • Hein Kruger Profile Picture
    629 on at

    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.

  • Verified answer
    Brad_P Profile Picture
    1,549 on at

    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,229

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,867 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,153 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans