Dictionary Data Type

Represents an unordered collection of keys and values. The Dictionary data type is optimized for fast lookup of values.

The following methods are available on instances of the Dictionary data type.

Method name Description
Count() Gets the number of key/value pairs contained in the Dictionary.
Keys() Gets a collection containing the keys in the Dictionary.
Values() Gets a collection containing the values in the Dictionary.
Get(TKey, var TValue) Gets the value associated with the specified key.
Get(TKey) Gets the value associated with the specified key.
Set(TKey, TValue) Sets the value associated with the specified key.
Set(TKey, TValue, var TValue) Sets the value associated with the specified key.
Add(TKey, TValue) Adds the specified key and value to the dictionary.
ContainsKey(TKey) Determines whether the Dictionary contains the specified key.
Remove(TKey) Removes the value with the specified key from the Dictionary.


Each addition to the dictionary consists of a value, and its associated key. Every key in a Dictionary must be unique. A key cannot be null, but a value can be, only when the value type is a reference type.

The Dictionary data type does not support holding instantiated records. For this purpose, use temporary tables.


Previously in C/AL, one would have typically used an in-memory temporary table to create a key-value data structure, as shown in the code below. In AL you use the Dictionary Data Type instead.

IF KeyCacheRec.GET(‘Some Value’)​ THEN​ 
    Complete data stack execution;


In the following example, the variable counter represents the Dictionary data type to store a value representing the number of occurrences for each character in the customerName. Using the Get method, you get the number of occurrences for the character at position i. If i returns false, it means there is no value associated with that character, so you add the value 1. If i returns true, it means the value already exists, so you add c + 1 to the value. The Add method adds the {key:value} pair to the Dictionary.

procedure CountCharactersInCustomerName(customerName: Text; var counter: Dictionary of [Char, Integer]);
    i : Integer;
    c : Integer;

    for i := 1 to StrLen(customerName) do 
        if counter.Get(customerName[i], c) then
            counter.Set(customerName[i], c + 1) 
            counter.Add(customerName[i], 1);

See Also

Getting Started with AL
Developing Extensions
List Data Type