Interview Questions

Tuesday, April 15, 2014

Dynamics Ax 2012 : Exploring the Containers

Dynamics Ax 2012 : Exploring the Containers

Apr 16, 2014
In Dynamics Ax there is structure known as containers. Here are some points for Containers
  • They are value based structure. So no class based object stored on it.
  • They are similar to linked list or array like structured.
  • Their size fixed at time of declaration. When you insert update or delete any value from container, a new container is created.
  • They always copied by value.
  • Containers are base 1 not like array based zero.
There is question arises why we use temporary tables when have containers . These containers which can stored almost very values data type value.  While there are lot of functions available for containers. Answer is that on temporary temple we can set indexes on fields and by this way we can fetch data much faster. Although data stored in container is sequentially but on insertion  a new copy is generated which is  performance over head. When data is increases in container, container starts to be heavy.  Similar when you passed temporary table to any method it passed by reference. But when we passed container to method, a new copy is generated and used in method. Container will used only when fewer values will be manipulated. In the case of larger set of data, we have to use temporary tables.

Declaration of containers.
container  firstContainer;

container  secondContainer = [3,"Ali","Gulshan"];

Read value from container.
The value from container can be read with conpeek function,  this method take two parameter, first one is container  and second parameter is for getting index. The conPeek function read value of any type so and read for any type.


_value  = conPeek(secondContainer,3);

 

Insert value:

There are two functions used for insert a value in container, conPoke and  conIns

ConIns


secondContainer=conIns(secondContainer,2,"Gupta");

 

conPoke:
 

secondContainer=conpoke(secondContainer,2,”test");

 
There difference between conPoke and conIns is that conIns, insert a new value at location, and rest of value is shifted to one next Index. conPoke replace the value at insert location for example if

container  secondContainer = [3,"Gulshan","Gupta"];
then conIns secondContainer=conIns(secondContainer,2,”Gupta”);  will create new conainter like as
[3,”Gupta”,”Gulshan”,”Kumar”];
While conPok
secondContainer=conpoke(secondContainer,2,”test”);
will create a [3,”Gupta”,”Gulshan”,”Kumar”];

[3,"test","Gulshan"];



Removing the value from Container:


Condel function is used to remove the value from container.

secondContainer =conDel(secondContainer,2,1);

conNull function is used to clear all the value from container as

secondContainer=conNull() ;

 
Length of container is calculated as

int _lenght= conLen(secondContainer);

confind:

This method find the index the value which required to search, if value is not found zero will be return

_found =conFind(secondContainer,"Gulshan");

info(int2str(_found));

_found =conFind(secondContainer,"Abc");



Some important Global class functions for Container


Con2Str:
This method return container values as comma sparated string.

_value = con2Str(secondContainer);

 
Con2List:
This function converts the container into list.
List _myList=con2List(secondContainer);


Loop through container:


Usually we have to loop through the container.


_lenght = conLen(secondContainer);

for (counter =1; counter <=_lenght; count++)

{

_value=conPeek(secondContainer,counter);

info(_value);

}

No comments:

Post a Comment