Understanding ConPoke() Function in Container in X++
☰Fullscreen
Table of Content:
conPoke Function:
- The conPoke() is used to modify a container by replacing one or more of the existing elements.
Syntax:
conPoke(container container, int start, anytype element, ...)
Parameters:
- container - The container to modify.
- start - The position of the first element to replace.
- element - One or more elements to replace, separated by commas.
Remarks
The first element of the container is specified by the number 1.
Return value:
- The new container with the inserted elements.
Example Code:
static void Container_conPokeExample(Args _args) { // container declaration and initialization with 2 values container containerName = ["Welcome", 1202]; // conPoke() function usage // (Replaces the value being held in a specific position in the container, with a new value) // Note: Here Replacing 2nd value (1202) with (29) in containerName containerName = conPoke(containerName, 2, 29); info(strFmt("Container containerName conPoke() values are :- %1, %2", conPeek(containerName, 1), conPeek(containerName, 2))); }
Output:
The above code will produce the following result-
Container containerName conPoke() values are :- Welcome, 29
Example 2:
class Container_conPokeExample { /// /// Class entry point. The system will call this method when a designated menu /// is selected or when execution starts and this class is set as the startup class. /// /// The specified arguments. public static void main(Args _args) { // container declaration and initialization with 5 values container salesOrders = ["SO1000001", "SO1000002", "SO1000003", "SO1000004", "SO1000005"]; salesOrders = conPoke(salesOrders, 2, "SO10000011"); setPrefix("Output"); for (int i = 1; i <= conLen(salesOrders); i++) { // Prints the content of the container. info(strFmt("%1", conPeek(salesOrders, i))); } } }
Output:
SO1000001 SO10000011 SO1000003 SO1000004 SO1000005
Example 3:
class Container_conPokeExample3 { /// /// Class entry point. The system will call this method when a designated menu /// is selected or when execution starts and this class is set as the startup class. /// /// The specified arguments. public static void main(Args _args) { // container declaration and initialization with 5 values container salesOrders = ["SO1000001", "SO1000002", "SO1000003", "SO1000004", "SO1000005"]; salesOrders = conPoke(salesOrders, 2, "SO10000011", "SO10000012"); setPrefix("Output"); for (int i = 1; i <= conLen(salesOrders); i++) { // Prints the content of the container. info(strFmt("%1", conPeek(salesOrders, i))); } } }
Output
SO1000001 SO10000011 SO10000012 SO1000004 SO1000005