Question & Answer
Question
How do I initialize a multidimensional array in Netcool/Impact?
Answer
Using braces ({}) notation you can assign array values as a comma-separated series of numeric, string, or Boolean literals:
arrayname = {element1, element2, elementn}
You can create an array of any size by manually defining its elements. You cannot import it from a file. You cannot have an array in an array, unless it is a multidimensional array.
You reference array elements using the square bracket notation. Use the following syntax to access the elements of a one-dimensional array and a multidimensional array, respectively:
arrayname[element index]
arrayname[first dimension element index][second dimension element index]
IPL arrays use a zero-based indexing system. This means that the first element of an array is identified by an index value of 0 instead of 1.
Here is an example of a one-dimensional array:
MyArray = {"Hello, World!", 12345};
Log(MyArray[0] + ", " + MyArray[1]);
It prints the following text to the policy log:
Hello.World!, 12345
Here in an example of a two-dimensional array:
MyArray = {{"Hello, World!", 12345}, {"xyz", 78, 7, "etc"}};
Log(MyArray[0][0] + "." + MyArray[1][0]);
It prints the following text to the policy log:
Hello.World!.xyz
This example policy makes use of the same two-dimensional array and prints the label and the value of an element to the parser log:
MyArray = {{"Hello, World!", 12345}, {"xyz", 78, 7, "etc"}};
log("MyArray is " + MyArray);
log("MyArray Length is " + length(MyArray));
ArrayA = MyArray[0];
log("ArrayA is " + ArrayA + " Length is " + length(ArrayA));
i = 0;
While(i < length(ArrayA)) {
log("ArrayA["+i+"] = " + ArrayA[i]);
i = i+1;
}
ArrayB = MyArray[1];
log("ArrayB is " + ArrayB + " Length is " + length(ArrayB));
i = 0;
While(i < length(ArrayB)) {
log("ArrayB["+i+"] = " + ArrayB[i]);
i = i+1;
}
Here is the output in the parser log for ArrayA:
ArrayA[0] = Hello World!
ArrayA[1] = 12345
You can also create the same two-dimensional array using JavaScript in Netcool/Impact 6.1. You can find an example of a JavaScript policy in the Netcool/Impact 6.1 Policy Reference Guide, under the section "Policy fundamentals > Policy-level data types> Complex data types> Array" at this URL:
http://publib.boulder.ibm.com/infocenter/tivihelp/v8r1/index.jsp?topic=/com.ibm.netcoolimpact.doc6.1/welcome.html
Was this topic helpful?
Document Information
Modified date:
17 June 2018
UID
swg21433195