Dear all,
I create a record variable, e.g:
TempItem :
DataType : Item
Dimension : 99
Temporary : Yes
Everytime I want to insert records to TempItem, I use this command :
Level := 1;
Clear(TempItem[Level]);
Item.SETRANGE(Item."No.",1000,5000);
Repeat
TempItem[Level].TransferFields(Item);
TempItem[Level].INSERT;
Until Item.Next = 0;
But the problem exists when I want to insert to the second dimension, so on ... :
Level := 2;
Clear(TempItem[Level]);
Message(Format(TempItem[Level].Count)); <-- Give me 5 instead of 0as the result
It seems that the TempItem[2] also has all records as TempItem[1], if I delete the records in this dimension, it also deletes all records in the first dimension. Please help me guys ... ](*,)
0
Comments
For any queries you can also visit my blog site: http://msnavarena.blogspot.com/
I know, that's weird, even after inside the loop (I loop after clear TempItem[2]), I give Message command to display the record, the second TempItem gives me the exact record as TempItem[1]. Any idea what's going on ?
This will only insert records in the first element of the array. You need to update the level variable while you're looping through the records.
Level := 1;
Item.SETRANGE(Item."No.",1000,5000);
Repeat
Clear(TempItem[Level]);
TempItem[Level].TransferFields(Item);
TempItem[Level].INSERT;
Level += 1;
Until Item.Next = 0;
I don't want to insert the second level yet ... I need to have dimension of temporary item tables, so that I can treat each of dimensions just like a temporary item tables. I need to populate item datas on the first dimension instead of one record for one dimension
Hi,
Actually there is no need to increase the level Level += 1; is not an issue here, the issue is different....array of records, while inserting the in the first array, it also inserts the same in the second array of the same type of records.......but weired :-k
I have tried with a lot of things but had no luck yet ](*,)
For any queries you can also visit my blog site: http://msnavarena.blogspot.com/
No
Had a go with this but I couldn't make it work. I suppose you could add another field to the item table.
Then you could do something like this:
Level := 1;
Item.SETRANGE("No.",'1000','5000');
IF Item.FIND('-') THEN
REPEAT
TempItem.TransferFields(Item);
TempItem.Level := Level;
TempItem.INSERT;
UNTIL Item.NEXT = 0;
This way instead of having an array which holds sets of items you have a set of items which can be seperated by filtering on the extra field.
Remco
For example I created test table with 2 fields, and wrote code on the form button:
As a result I have 4 messages with 'exist' and this is completely illogical. The data which I inserted in TestTableTmp[2] exists for all elements of array. I tested it on NAV 5 and NAV 2009, it was no difference. So, NAV doesn't work properly with array of temporary records.
I think NAV creates a temporary table as a copy of a physical table on the client side. This copy will have an ID starting at 2000100000. The ID is increased by the no. of temporary tables (instances) you create. But if you want to use your temporary record variable as an array then NAV will only create one copy of your table. Not one for each dimension of the array like expected.
Suppose you have a table. A real table. With data and all. Like 5 customers. Now if you create a variable called "Customer" and define it as an array, you expect that both, Customer[1] and Customer[2] contain the same data, don't you?
The same applies for temporary tables. A temporary table behaves in exactly the same way as you would expect from a normal table, except that their data is stored in system memory. So referencing TempCustomer[1] gives you the same set as TempCustomer[2].
Besides: Did you know you can CALCSUMS on every field in a temporary table, even if you don't set the correct key / the field itself is not specified in any key? Handy!
A temporary table is a complete different thing. It's more comparable to a memory map of a physical table structure. And its behaviour of record arrays and single record variables differs. The data stored in record arrays like TempCustomer[1]/TempCustomer[2] will end up on the same memory area, but the data entered into single record variables like TempCustomer1/TempCustomer2 is stored in different places.
So, when you say you expect the same behaviour in the part of usage of temporary record variables you mentioned, then I would expect the same behaviour in all parts of usage.
It's a bug, but also a feature.
http://dynamicsuser.net/blogs/mark_brummel/archive/2010/05/05/tip-27-using-temp-tables-in-arrays.aspx
http://www.mibuso.com/howtoinfo.asp?FileID=22 (go to the end of the document)