Understanding conIns() Function in Container in X++

Rumman Ansari   Software Engineer   2024-07-18 09:24:07   7456  Share
Subject Syllabus DetailsSubject Details
☰ TContent
☰Fullscreen

Table of Content:

conIns Function

  • The conIns() is used to insert one or more elements into a container.

Syntax:


container conIns(container container, int start, anytype element, ...)

Parameters

  • 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.


Example:

Code:


static void Container_conInsExample(Args _args)
{
    // container declaration and initialization with 2 values
    container containerName = ["Welcome", 1202]; 
    str charHolder;
    ;

    // conIns() function usage 
    // (Inserts a value into a specific position in the container, index shifted next)
    // Note: Here Inserting value 299 at 2nd location and shifting the rest to the right!
    containerName = conIns(containerName, 2, 200);
    info(strFmt("Container containerName conIns() values are :- %1 , %2, %3", 
    conPeek(containerName, 1), conPeek(containerName, 2), conPeek(containerName, 3)));
}

Output:

The above code will produce the following result-


Container containerName conIns() values are :- Welcome , 200, 1202

Another Example


class Container_conInsExample
{
   public static void main(Args _args)
   {
       // container declaration and initialization with 2 values
       container containerName = ["Welcome", 1102];         
               
       containerName = conIns(containerName, 2, 200, 3000, "Hello", 3.14);
 
       for (int i = 1; i <= conLen(containerName); i++)
       {
           // Prints the content of the container.
           info(strFmt("%1", conPeek(containerName, i)));
       }
   } 
}

Output


Welcome
200
3000
Hello
3.141102
1102