AX Consulting

Just another WordPress.com site

Types of MAP in dynamics

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()));
    }
}

References:
http://msdn.microsoft.com/en-us/library/aa553382.aspx

2. AOT Maps: A map can unify the access to similar columns and methods that are present in multiple tables. You associate a map field with a field in one or more tables. This enables you to use the same field name to access fields with different names in different tables. Methods on maps enable you to create or modify methods that act on the table fields that the map references.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: