In the AL language for Microsoft Dynamics 365 Business Central, the List Data Type represents a strongly typed list of ordered objects accessible by index. Lists are unbounded, meaning their dimension (size) is not specified when declared.
A List can only be declared with simple types (Byte, Boolean, Char, Code, Date, DateFormula, DateTime, Decimal, Text, Time, etc.) and does not support holding instantiated records.
Lists are an efficient way to create and manage unbounded data structures with many practical uses.
Only a few days pass when I do not find a reason to use lists. One of my recent uses for a List was to store and process each unique value found in a delimited text value. For this, I split the delimited text into separate values and then copied them to a new list removing duplicates.
In this example, a value delimited by a comma (‘,’) or pipe (‘|’) is split into a list of unique values.
procedure SplitValues()
var
UniqueValues: List of [Text];
DelimitedText: Text;
value: Text;
begin
DelimitedText := '12,34,56,24|12,56,89,56,23|12,34,22,34';
UniqueValues := SplitUniqueValues(DelimitedText);
foreach value in UniqueValues do
Message(value);
end;
local procedure SplitUniqueValues(DelimitedText: Text): List of [Text]
var
UniqueValues: List of [Text];
Values: List of [Text];
Delimiters: Text;
value: Text;
begin
Delimiters := ', |';
Values := DelimitedText.Split(Delimiters.Split(' '));
foreach value in Values do
if not UniqueValues.Contains(value) then
UniqueValues.Add(value);
exit(UniqueValues);
end;
Learn more about the List Data Type Here
Note: The code and information discussed in this article are for informational and demonstration purposes only. This content was created referencing Microsoft Dynamics 365 Business Central 2023 Wave 1 online.
*This post is locked for comments