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.
Find a job at: www.DynamicsAXJobs.com
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.
Find a job at: www.DynamicsAXJobs.com
4 Comments:
Speaking of maps. What are their limits speaking of no of entries? total space in map?
As you are waiting with RecId's in your example, you should be carefule with using Integer as Type ... changed since version 4 :-)
One approach I use is the following:
DictType dt = new DictType(extendedTypeNum(recid));
map = new Map(dt.baseType(),Types::Integer);
br Karsten
I think you are calling a needless line. MarkMap.valueSet() returns a set. You aren't doing anything with it, so it is misleading.
Unless I'm misunderstanding the purpose of your code.
http://msdn.microsoft.com/en-us/library/aa591362.aspx
Alex you are correct actually that line of code is not needed.
Post a Comment
<< Home