Wednesday, July 8, 2020

Container in Ax 2012

A container is an abstract data type (ADT) whose instances are collections of other objects.
In other words, they store objects in an organized way that follows specific access rules. The size of the container depends on the number of objects (elements) it contains.

Declare a container :
container cr3;

Assign a literal container to a container variable :
cr3 = [22, "blue"];

Declare and assign a container :
container cr2 = [1, "blue", true];

Mimic container modification (implicitly creates a copy) :
cr3 += [16, strMyColorString];
cr3 = conIns(cr3, 1, 3.14);
cr3 = conPoke(cr3, 2, "violet");

Assignment of a container (implicitly creates a copy) : 
cr2 = cr3;

Read a value from the container : 
myStr = conPeek(cr2, 1);

One statement that does multiple assignments from a container
str myStr;
int myInt;
container cr4 = ["Hello", 22, 20\07\1988];
[myStr, myInt] = cr4; // "Hello", 22


condel   :- Use condel to delete one or more items from a container.
confind :- Use confind to locate a sequence of items in a container. 
conins   :- Use conins to insert some items into a container.
conlen   :- Use conlen to find out how many items there are in a container.
connull  :- Use connull to explicitly dispose of the contents of a container.
conpeek :- Use conpeek to extract an item from a container, and to convert it into another data type  
conpoke :- Use conpoke to replace (poke) an item in a container.

Difference between temp table and container.
1. Data in containers are stored and retrieved sequentially, but a temporary table enables you to define indexes to speed up data retrieval.
2. Containers provide slower data access if you are working with many records. However, if you are working with only a few records, use a container.
3. Another important difference between temporary tables and containers is how they are used in method calls. 
When you pass a temporary table into a method call, it is passed by reference. Containers are passed by value. When a variable is passed by reference, only a pointer to the object is passed into the method. When a variable is passed by value, a new copy of the variable is passed into the method. If the computer has a limited amount of memory, it might start swapping memory to disk, slowing down application execution. When you pass a variable into a method, a temporary table may provide better performance than a container