I'll be honest, I found this out by accident lately but I want to share it anyway. Since it took me almost 15 years to find, it might not be know to some others.
As many of you know, using temporary tables in Microsoft Dynamics NAV is a very powerfull feature. We can use it to buffer data, to simulate SELECT DISTINCT etc. And they are free.
Using temporary tables becomes even more powerfull when adding an array to it. Let's see this in an example.
We'll create a new codeunit with a variable CustTemp that has two dimensions.
So now we can use CustTemp and CustTemp.
Let's write some C/AL Code with this.
We create a new record using CustTemp. We then try a FINDFIRST on CustTemp. Let's see what message we get.
How cool is this! The contents of the CustTemp is the same as that of CustTemp.
So what can we do with this. Let's add some more code.
We add a new record to CustTemp and filter on this value using CustTemp. Then we show the value of Name and the number of records in CustTemp.
What does this give?
The CustTemp now has the value of the Name we insterted in CustTemp. CustTemp ignores the filter we used in CustTemp.
Ok Mark, great stuff but what can I do with this?
Microsoft uses this in at least two places in the standard Navision product.
The fist place is the UpdInvPostingBuffer() function in Codeunits 80 and 90. This temporary buffer variable has two dimensions which are used to combine a select distinct with a total of the values.
The second place is the Inventory Profile Offsetting Codeunit (99000854) in Navision Manufacturing. In this codeunit supply and demand is created in the InventoryProfile table.
I already knew this for a long time and use this 'bug' a lot.
I also mentioned it in my how to : www.mibuso.com/howtoinfo.asp
The array technique can also be used on temporary record-variables. They work also independently of each other like on a real table. BUT THERE IS ONLY 1 TEMPTABLE! This means that if you create a record with element , it will be available in element ! An example (This is the very first code on the temptable, so there are no records in it!).
recRecord."No." := '1');
MESSAGE('%1',recRecord."No."); // this will show the value of the record I
created in element !
But I have to admit I never new it was a bug.....
When I first found out how this worked, I thought it was correct functioning, because if you insert a record in element 1 of the array on a real table, it is available in element 2 of the array. So it seemed logical that the temptable-array follows this logic.