Work with Memory Collections in Business Central AL

Hello, I’m a beginner in AL coding Business Central. I would like to create a procedure with 2 complex type of collections parameter and the result should be 1 complex type of collection also.I should get parameters collections from web API, and send back the result via API also. My Question is how can I define these complex type without databasetable and work with them in memory?

I have cretate one sampler code in C#:

class Storage{ 
           public  decimal Quantity { get; set; }

            public string Item { get; set; }

 class Order {
            public int OrderId { get; set; }
            public decimal Quantity { get; set; }
            public string Item { get; set; }

        /// <summary>
        /// Check Sotrage to Summorized Orders
        /// </summary>
        /// <param name="storage">Storgate of Items </param>
        /// <param name="orders">Ordered Items</param>
        /// <returns>List of orders what we can’t complete together</returns>
  List<Order> Calculation(List<Storage> storage, List<Order> orders)
            //Order what I can't complate
            var _result = new List<Order>();

            //Summarized Demand by Item
            var _sumDemands = orders.GroupBy(g => g.Item).Select(s => new Order { Item = s.Key, Quantity = s.Sum(z => z.Quantity) });
            foreach (var _demand in _sumDemands)
                //We don't have enough sotrage to complate all of orders 
                // I don't care if I posible to complate one of them 
                if (!storage.Any(s => s.Item == _demand.Item) || storage.FirstOrDefault(s => s.Item == _demand.Item).Quantity < _demand.Quantity)
                    foreach (var _order in orders.Where(w => w.Item == _demand.Item))

            return _result;

Thank you!


Hi Gergely,

Welcome to DUG! I’m not really a C# programmer my self, so from the code snippet you have included, then I cannot see what you really are asking. The code you have doesn’t look very different from what you could do in AL. Even if you would do it differently.

Could you come with examples (not in code but in words) of what it is you are trying to do?

Did you try using Arrays? It is not so simple in AL as in C# !:slight_smile:

Try use temp tables. They are good instead of arrays in NAV

As a new developer, then you may also be interested in this site - it’s not updated for AL, but covers use of many well-known design patterns from other languages, and some of the different ways we have to do easy things in other languages. They mostly still apply.