Hi All,
I hope you are doing well. It's feels like forever since I wrote a blog! Although, here I am with an another one. :)
We have always been talking about a different way of passing a value - Pass by reference but how do we use it in AL and for what kind of variables, well let's find out!
Business Central is extending in terms of types of datatypes and objects and sky is the limit.
Let's talk about a Datatype 'List' which gives you more flexibly and functions than an array. Now, what if you want to return the List?
Something like this doesn't work like it does for other datatypes:
procedure Passvalue(var SomeTableVariable: Record "Some Table") : List
For a case like this, Pass by Reference helps you to achieve this. Let's see how we can do that:
1. Create a function to which you'll add values to your List:
2. Create a function wherein you'll pass the create List:
3. Call these two functions one after the other wherever you want to get this List, say onClosePage():
Note: What happens here is that you create a List variable and it is empty initially, then you pass this empty List to the first function which will add values to the list. The second function is passed with the filled list because it is been passed as reference 'var'.
This is how you get the values of a List or any variable that called be directly returned to the function and the simple answer is 'Pass by Reference' !
No comments:
Post a Comment