Dimension Record Variable Problem

ayashiayashi Member Posts: 78
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 ... ](*,)

Comments

  • diptish.naskardiptish.naskar Member Posts: 360
    Well I can just say this much that no values are inserted in Level 2 when you are excuting the Level 1. I mean to say that they are blank records and donot contain any value. Try to put a messagebox for Level2 and 1 inside the loop and you will find out what I am trying to say.
    Diptish Naskar
    For any queries you can also visit my blog site: http://msnavarena.blogspot.com/
  • ayashiayashi Member Posts: 78
    hi diptish,

    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 ?
  • remco_rauschremco_rausch Member Posts: 68
    Level := 1;
    Clear(TempItem[Level]);
    Item.SETRANGE(Item."No.",1000,5000);
    Repeat
    TempItem[Level].TransferFields(Item);
    TempItem[Level].INSERT;
    Until Item.Next = 0;

    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;
  • ayashiayashi Member Posts: 78
    hi remco,

    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
  • diptish.naskardiptish.naskar Member Posts: 360
    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;

    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 ](*,)
    Diptish Naskar
    For any queries you can also visit my blog site: http://msnavarena.blogspot.com/
  • ayashiayashi Member Posts: 78
    do you think this is the limitation of navision ? we can't use array if the datatype is record ... #-o
  • MbadMbad Member Posts: 344
    ayashi wrote:
    do you think this is the limitation of navision ? we can't use array if the datatype is record ... #-o

    No
  • remco_rauschremco_rausch Member Posts: 68
    Ah I see what you're trying to do, I should really learn to read questions properly.

    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
  • SolmyrSolmyr Member Posts: 51
    I faced with the similar problem.
    For example I created test table with 2 fields, and wrote code on the form button:
    TestTableTmp: Record 50001;
    Dimensions: 4
    Temporary: Yes
    
    TestTableTmp[1].RESET;
    TestTableTmp[2].RESET;
    TestTableTmp[3].RESET;
    TestTableTmp[4].RESET;
    
    TestTableTmp[1].DELETEALL;
    TestTableTmp[2].DELETEALL;
    TestTableTmp[3].DELETEALL;
    TestTableTmp[4].DELETEALL;
    
    TestTableTmp[2].INIT;
    TestTableTmp[2]."No." := '1';
    TestTableTmp[2].Text1 := 'dim 1';
    TestTableTmp[2].INSERT;
    
    IF TestTableTmp[1].ISEMPTY THEN
      MESSAGE('1 - empty')
    ELSE
      MESSAGE('1 - exist');
    
    IF TestTableTmp[2].ISEMPTY THEN
      MESSAGE('2 - empty')
    ELSE
      MESSAGE('2 - exist');
    
    IF TestTableTmp[3].ISEMPTY THEN
      MESSAGE('3 - empty')
    ELSE
      MESSAGE('3 - exist');
    
    IF TestTableTmp[4].ISEMPTY THEN
      MESSAGE('4 - empty')
    ELSE
      MESSAGE('4 - exist');
    

    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.
    Oleg Dovgalenko
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    I'm facing with the same problem. I think it's a :bug:.
    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.
    FOR i := 1 TO 2 DO BEGIN
      RecRef.GETTABLE(TempContact[i]);
      MESSAGE('%1',RecRef.NUMBER);
    END;
    
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • ahed4ahed4 Member Posts: 21
    You can use array's with records. And actually it is not weird at all:

    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!
    The freaks come out at night.
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    I don't think it's comparable to a normal record variable. In a simplified point of view a record variable is nothing else but a view to physical existing data. And of course unfiltered record variables of the same subtype will show you the same data. That applies to record arrays like Customer[1]/Customer[2] as well as to single record variables like Customer1/Customer2.

    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.
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • kapamaroukapamarou Member Posts: 1,152
    If I remember correctly, even in standard NAV, when an array of a temporary record is used, the command INSERT is not executed. If you want to use an array for comparison or any other reason, don't call INSERT. This will make all elements the same.
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    Today I found an explanation to it in another topic by Mark Brummel.
    It's a bug, but also a feature. :wink: If you know how to deal with it you could consider it in your development.
    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)
    "Money is likewise the greatest chance and the greatest scourge of mankind."
Sign In or Register to comment.