Understanding ConFind() Function in Container in X++
☰Fullscreen
Table of Content:
conFind Function
- 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,... )
Parameters:
- container - The container to search.
- element - One or more elements to search for, separated by commas.
Remarks
If several elements are specified in the sequence, they must be separated by commas and specified in the correct sequence. The elements can be of any data type.
Return value:
- Returns 0 if the item was not found; otherwise, the sequence number of the item.
Example:
Code:
static void Container_conFindExample(Args _args) { // container declaration and initialization with 2 values container containerName = ["Welcome", 1202]; str charHolder; ; // conFind() function finds position in the container that a certain value is being held (if found) info(strFmt("conFind() - Find '1202' value in containerName container return if true(indexNo) else (0):- %1", conFind(containerName, 1202))); info(strFmt("conFind() - Find '2' value in containerName container return if true(indexNo) else (0):- %1", conFind(containerName, 2))); }
Output:
The above code will produce the following result-
conFind() - Find '1202' value in containerName container return if true(indexNo) else (0):- 2 conFind() - Find '2' value in containerName container return if true(indexNo) else (0):- 0
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"]; int position; position = conFind(salesOrders, "SO1000002"); setPrefix("Output"); // Prints the content of the container. info(strFmt("%1", position)); } }
Output
Output 2
Example 3
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"]; int position; position = conFind(salesOrders, "SO1000002", "SO1000002"); setPrefix("Output"); // Prints the content of the container. info(strFmt("%1", position)); } }
Output
Output 2
Example 4
class Container_conFindExample { /// /// 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"]; int position; position = conFind(salesOrders, "SO1000002", "SO1000004"); setPrefix("Output"); // Prints the content of the container. info(strFmt("%1", position)); } }
Output
Output 0