Thursday 10 December 2015

Containers in Ax

Container

   X++ (Object oriented programming language) the data or values 
   stored in a Variable are of below types:
  • Primitive dataTypes - int, str, real .... etc.
  • Composite dataTypes - Arrays, Containers, Collection Classes
Container Functions

1.ConPeek( )
  • The conPeek() is used to retrieve a specific element from a container.
  • Syntax: anytype conPeek(container container, int number)
    • container - The container to return an element from.
    • number - The position of the element to return. 
                               Specify 1 to get the first element.
  • Return value: The element in the container at the position specified
 by the number parameter. The conPeek function automatically converts
 the peeked item into the expected return type.
Ex :   static void Ex_Conpeek(Args _args)
         {
               container   c = ['Test', 27,'Rajendra',10.000000000];

               info(strFmt('%1 - %2', conPeek(c, 1), conPeek(c, 2)));
               info(strFmt('%1 - %2', conPeek(c, 1),conPeek(c, 3)));
               info(strFmt('%1 - %2', conPeek(c, 1),conPeek(c, 4)));
         }
























2.ConPoke( )

  • The conPoke() is used to modify a container by replacing 
        one or more of the existing elements.
Syntax: 
  • container conPoke(container container, int start, anytype element, ...)
    • container - The container to modify.
    • start - The position of the first element to replace.
    • element - One or more elements to replace, separated by commas.
  • Return value: The new container with the inserted elements.

Ex : static void Ex_Conpoke(Args _args)
       {
            container   con = ["Rajendra",123]; //intial data 
            con     = conPoke(con,2,143143);  // after modification Done
            info(strFmt("%1 - %2",conPeek(con,1),conPeek(con,2)));
        }

























3.ConIns()
  • conIns() is used to insert one or more elements into a container.
  • Syntax: container conIns(container container, int start, anytype element, ...)
    • container - The container into which to insert elements.
    • start - The position at which to insert elements.
    • element - One or more elements to insert, separated by commas.
  • Return value: The new container with the inserted elements.
Ex : static void Ex_ConIns(Args _args)
{
    container   con = ["Rajendra",410];//intial container Data
    con = conIns(con,3,123456);       //After Data Inserted into Container
    info(strFmt("%1 - %2 - %3",conPeek(con,1),conPeek(con,2),conPeek(con,3)));
}

















4.ConFind( )

  • The conFind() is used to find the first occurrence of an element or a sequence of elements in a container.
  • Syntax: int conFind (container container, anytype element,... )
    • container - The container to search.
    • element - One or more elements to search for, separated by commas.
  • Return value: Returns 0 if the item was not found; otherwise, the sequence number of the item.
Ex:   static void Ex_ConFind(Args _args)
  {
        container   con = ["Rajendra",410];
    // conFind() function finds position in the container that a certain value
    info(strFmt("410 is found at position %1   - Rajendra is found at position %2",conFind(con,410),conFind(con,"Rajendra")));
}


















5.ConLen( )
  • The conLen() is used to retrieve the number of elements in a container.
  • Syntax: int conLen(container container)
    • container - The container in which to count the number of elements.
  • Return value: The number of elements in the container.
Ex : static void Ex_ConLen(Args _args)
{
    container   con = ["Rajendra",123,'A',4.2525];
    info(strFmt("Length of a Container is %1",conLen(con)));
}

















6.ConDel( )
  • The conDel() is used to remove the specified number of elements from a container.
  • Syntax: container conDel(container container, int start, int number)
    • container - The container from which to remove elements.
    • start - The one-based position at which to start removing elements.
    • number - The number of elements to delete.
  • Return value: A new container without the removed elements.
Ex: static void Ex_ConDel(Args _args)
{
    container   con = ["Rajendra",1254];
    con =  conDel(con,2,1);
    info(strFmt("%1--%2 ",conPeek(con,1),conPeek(con,2))); // 0 indicates that 1254 has been deleted & no element is there

}

















7.Connull( )
  • The conNull() is used to retrieve an empty container. Use this function to explicitly dispose of the contents of a container.
  • Syntax: container conNull()
  • Return value: An empty container.
Ex : static void Ex_ConNull(Args _args)
{
    container   con = ["Hello","Welcome","To","Ax",2012,"R3"];
    info(strFmt("Container conNull()  before : %1 - %2 - %3 - %4
 - %5 -%6",conPeek(con,1),conPeek(con,2),conPeek(con,3),conPeek(con,4)
,conpeek(con,5),conPeek(con,6))); 

    con = conNull(); //clears the container

    info(strFmt("Container conNull()  after  : %1 - %2 - %3 - %4 - %5 - %6",conPeek(con,1),conPeek(con,2),conPeek(con,3),conPeek(con,4),
conpeek(con,5),conPeek(con,6)));
    
}


No comments:

Post a Comment