Nested (2 dimensional) Array

Hi,

long, long time ago I saw (and used) a solution for a 2 dimensional array in Axapta (2.5)

I cannot find that solution anymore, searched on the internet but cannot find.

It was something like an array of arrays. Simple and straightforward, but worked.

There’s one solution around on internet (with a macro etc) but that one is too difficult.

So anybody here who can recall such a method of an array of arrays?

Thanks

Which version of AX do you mean? (Please always attach a tag with the version, e.g. AX 2012).

A good solution may be using .NET arrays through .NET Interop from X++. Like this:

System.String[,] a = new System.String[4,4]();
a.SetValue("test", 0, 0);

Note that .NET Interop was introduced in AX 4.0 and it has been improved in later versions.

Regarding “one solution around on internet (with a macro etc)”, you seem to mean Multiple Array Indexes in AX documentation. It’s not really difficult - let me try to explain it once more.

Imagine that you want a matrix with 4x4 elements. AX natively supports only one-dimensional arrays, so you can simply put all 16 elements (4x4) into a single one-dimensional array. You’ll consider first 4 elements to be the first row, elements 5-8 the second row and so on.

Macros aren’t necessary; I would rather wrap the logic in a class anyway.

Will do next time.

Cannot edit the tags anymore.

I’m working with Axapta 3.0

Thanks MArtin.

Working with Axapta 3.0 this is a nogo unfortunately

Aha, you explain it in a logical way, thanks.

It’s still difficult to read however, I think.


I fired up an old backup and found the method. (I’m happy :slight_smile:

Its like this:

static void NestedArray(Args _args)
{
    array   array;
    int     i;
    ;
 
    array = new Array(Types::class);
 
    for(i = 1;i < 5; i++)
        {
        array.value(i, new Array(Types::STRING));
        array.value(i).value(1,'a' + int2str(i));
        array.value(i).value(2,'b' + int2str(i));
        array.value(i).value(3,'c' + int2str(i));
        array.value(i).value(4,'d' + int2str(i));
        array.value(i).value(5,'e' + int2str(i));
        }
 
    for(i = 1;i < 5; i++)
        {
        info(strfmt("%1",array.value(i).value(1)));
        info(strfmt("%1",array.value(i).value(2)));
        info(strfmt("%1",array.value(i).value(3)));
        info(strfmt("%1",array.value(i).value(4)));
        info(strfmt("%1",array.value(i).value(5)));
        info("");
        }
}