Types of MAP in dynamics AX

There are two types of Maps available in dynamics AX

1. X++ Maps: it can be used as a temp data store for the given scope of a process. This takes us less over head, and is much quicker than a TempTable.
Map class allows you to associate one value (the key) with another value. Both the key and value can be any valid X++ type, including objects. The types of the key and the value are specified in the declaration of the map. The way in which maps are implemented means that access to the values is very fast.
Below is a sample code that sets and retrieves values from a map.


 

static void checkItemNameAliasDuplicate(Args _args)
{
    inventTable         inventTable;
    Map                 map;
    MapEnumerator       mapEnumerator;
    NameAlias           nameAlias;
    int                 counter = 0;
    ;

    map = new Map(Types::String, Types::Integer);

    //store into map
    while select inventTable
    {
        nameAlias = inventTable.NameAlias;
        if (!map.exists(nameAlias))
        {
            map.insert(nameAlias, 1);
        }
        else
        {
            map.insert(nameAlias, map.lookup(nameAlias) + 1);
        }
    }


    //retrieve from map by using MapEnumerator
    mapEnumerator = map.getEnumerator();
    while (mapEnumerator.moveNext())
    {
        nameAlias       = mapEnumerator.currentKey();
        info(strfmt("%1,%2",mapEnumerator.currentKey(),mapEnumerator.currentValue()));
    }
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.