Map & MapEnumerator Objects

Something that I find myself using a lot in code is Map and MapEnumerator objects. Back when I first started in Ax we use to store values in tempTables. This still has it's place, but it's more over head than using a Map. A Map, or several of them, 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 Temp. Table.

I have used maps in different locations, but the point of a map is to store whatever values you need to, and at a given point act on those values. Below are two code examples. The first is an example of how to create a map, and insert values into it:

Map Example:

Map m;
;

m = new Map(Types::Integer,Types::Integer);

MarkMap.insert(InventTable.RecId,_markSKUs);
MarkMap.valueSet();

Below here is code for taking a known key value and lookup the corresponding value assoicated with the given key:

MarkMap.exists(InventTable.RecId)
MarkMap.lookup(InventTable.RecId)

This is a wonderful way to look up the value because you have the exact key. What if you wanted to transverse or enumrate through a given map to act on each value. This would be similar to moving through a resultset, etc:

MapEnumerator ME;
;

ME = new MapEnumerator(MarkMap);
while(ME.moveNext())
{
// .. preform some logic ..}
With this you can now walk through or enumrate through a given map and act upon each value stored in it. Like I said, Maps are very cool, easy to use, and much faster and preferred than using a temp table. Check back soon for more posting on code examples, how to's, etc.

No comments:

Post a Comment

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