Introduction:
Array is a collection of same data type variables. We can
access the each element in the array by using index. The index is start with 1.
Sometimes, we have to deal with same data type value collections like name of
the persons. For this scenario, we can use array data type.
Array data type is one of the composite data type in AX
2012. We can’t use Array data type for store the class objects. But, we can use
Array collection class instead of Array data type.
AX 2012 supports only single dimension array not multi
dimension array.
Array example:
static void Hari_TestJob(Args _args)
{
str empName[10]; // Fixed-length array with 10 integers
empName[1] =
'Hari'; //Assign value to the 1st
element in the array
print empName[1]; //Accessing the 1st element in the
array
pause;
}
Types of array
Three types of arrays are in AX.
- Fixed length
- Dynamic length
- Partly on disk
Fixed length:
Declare the length of the array in the variable declaration
section. For example:
str empName[10];
As per the above declaration code, we can hold only 10
values in this array.
Dynamic length:
Declare the array without mention the length. For example:
str empName[];
Array length is the unlimited here. Array length is
calculated based on the maximum element index used.
Partly on disk:
Partly on disk is some elements occupied in memory and others
are occupied on disk. We can use fixed length array and dynamic length array in
the partly on disk type. We can use this type for performance optimization when
deal with lot of data. For example:
//Fixed length
array in the partly on disk array type,
//here 20 items in
the memory and 100 items in the disk.
str empName[100,
20];
//Dynamic length
array in the partly on disk array type,
//here 20 items in
the memory and other items in the disk.
str empName[, 20];
Reset the array
values:
We can reset all array element value by assign any value to
the 0 element of the array. For example:
static void Hari_TestJob(Args _args)
{
str empName[10];
empName[1] =
'Hari';
empName[0] = ''; // Reset the array values
print empName[1];
pause;
}
Get
the array length:
We can get the length of
the array by using the dimOf function.