AL: Lists and Dictionaries

TallyHo
Member Posts: 417
I've been looking for a good way to use the new variable types List and Dictionary to replace the use of temporary tables.
If anyone here has code snippets to share on how to implement those new buffering tools in more complex ways it would be very welcome! So far I came up with this:
// Welcome to your new AL extension.
// Remember that object names and IDs should be unique across all extensions.
// AL snippets start with t*, like tpageext - give them a try and happy coding!
pageextension 50100 CustomerListExt extends "Customer List"
{
trigger OnOpenPage();
var
myDictionary: Dictionary of [code[20], Decimal];
myListOfLists: List of [List of [code[20]]];
myListOfDictionaries: List of [Dictionary of [code[20], Decimal]];
i: Integer;
j: Integer;
begin
myDictionary.Add('A', 2.432);
myDictionary.Add('B', 0.037);
myDictionary.Add('C', 1.234);
myListOfDictionaries.Add(myDictionary);
clear(myDictionary);
myDictionary.Add('A', 1.425);
myDictionary.Add('B', 9.333);
myDictionary.Add('C', 0.123);
myListOfDictionaries.Add(myDictionary);
clear(myDictionary);
myDictionary.Add('A', 0.134);
myDictionary.Add('B', 3.234);
myDictionary.Add('C', 7.334);
myListOfDictionaries.Add(myDictionary);
for i := 1 to myListOfDictionaries.count do begin
myDictionary := myListOfDictionaries.get(i);
for j := 1 to myDictionary.Count do begin
message('%1', myDictionary.get('A'));
end;
end;
end;
}
If anyone here has code snippets to share on how to implement those new buffering tools in more complex ways it would be very welcome! So far I came up with this:
// Welcome to your new AL extension.
// Remember that object names and IDs should be unique across all extensions.
// AL snippets start with t*, like tpageext - give them a try and happy coding!
pageextension 50100 CustomerListExt extends "Customer List"
{
trigger OnOpenPage();
var
myDictionary: Dictionary of [code[20], Decimal];
myListOfLists: List of [List of [code[20]]];
myListOfDictionaries: List of [Dictionary of [code[20], Decimal]];
i: Integer;
j: Integer;
begin
myDictionary.Add('A', 2.432);
myDictionary.Add('B', 0.037);
myDictionary.Add('C', 1.234);
myListOfDictionaries.Add(myDictionary);
clear(myDictionary);
myDictionary.Add('A', 1.425);
myDictionary.Add('B', 9.333);
myDictionary.Add('C', 0.123);
myListOfDictionaries.Add(myDictionary);
clear(myDictionary);
myDictionary.Add('A', 0.134);
myDictionary.Add('B', 3.234);
myDictionary.Add('C', 7.334);
myListOfDictionaries.Add(myDictionary);
for i := 1 to myListOfDictionaries.count do begin
myDictionary := myListOfDictionaries.get(i);
for j := 1 to myDictionary.Count do begin
message('%1', myDictionary.get('A'));
end;
end;
end;
}
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions