[solved] Temp record variable and RESET

CobaltSSCobaltSS Member Posts: 137
Hi all,

The function below comes from CodeUnit 22, and is called from Codeunit 5705. My questions are what happens to a TEMP variable when a RESET is applied against it, and what is the impact of doing that as the first step in the function?
CollectItemEntryRelation(VAR TargetItemEntryRelation : TEMPORARY Record "Item Entry Relation") OK : Boolean
TempItemEntryRelation.RESET;
TargetItemEntryRelation.RESET;

IF NOT TempItemEntryRelation.FIND('-') THEN
  EXIT(FALSE)
ELSE
  REPEAT
    TargetItemEntryRelation := TempItemEntryRelation;
    TargetItemEntryRelation.INSERT;
  UNTIL TempItemEntryRelation.NEXT = 0;

TempItemEntryRelation.DELETEALL;

EXIT(TRUE);

cheers,

Comments

  • krikikriki Member, Moderator Posts: 9,110
    A VAR parameter for a record also sends the filters to the function.

    The RESET removes the filters and selects the primary key on the temptable, BUT DOES NOT TOUCH the records itself that are in the temptable.

    So REPEAT-UNTIL will read all records that are in the temptable passed to the function by the calling program.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • CobaltSSCobaltSS Member Posts: 137
    So in the function, the RESET on the first, TEMP var, should do nothing and should have no records, because it's not passed? The second line of the function is the passed variable. Then the IF statement references the TEMP var in the first line, so it's always FALSE?

    cheers,
  • krikikriki Member, Moderator Posts: 9,110
    If the calling program has records in its temptable and passes it to this function as the first parameter, the VAR makes sure the temptable has the same records and filters as the in the calling program.
    So doing a RESET removes the filters, BUT IT DOESN'T TOUCH the records in the temptable.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • CobaltSSCobaltSS Member Posts: 137
    Hi Alain,

    I understand the RESET doesn't affect the values within the record variable, just the filters and keys. However, I'm a bit confused about what's happening within the function. Sorry for being obtuse.
    There are 2 record variables involved in this function. This one is passed TargetItemEntryRelation to the function from another Codeunit. The function's first line is to RESET a differenet TEMP record TempItemEntryRelation.RESET;
    which to me means there should be no records in TempItemEntryRelation because the called function is not part of a single instance codeunit, and TempItemEntryRelation is not part of a function call. Am I right? Then there's the FIND line on the (in my mind anyway) TEMP var, which should be false, but because of the NOT, is always true.
    Maybe because it's Monday, but it's all clear as mud to me. Any insight greatly appreciated.

    cheers,
  • kinekine Member Posts: 12,562
    The variable "TempItemEntryRelation" is global variable in the codeunit. Records are inserted into this temporary table with another function in the same codeunit. This function is just copying the records from this temporary table into passed variable to be able to access these records from outside of this codeunit (you can access just functions, not global variables from outside...).
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • CobaltSSCobaltSS Member Posts: 137
    I see now where the Codeunit was called earlier, so yes there are records in the TEMP record.

    Thanks for your time, both of you.

    cheers,
  • kinekine Member Posts: 12,562
    You are welcome... :D
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • krikikriki Member, Moderator Posts: 9,110
    At your service :D
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.