Why search for last record in No. Series Line table?

lvanvugtlvanvugt Member Posts: 774
Due to the occurrence of too many locks on the No. Series Line table we stumbled over the following code in COD5704 and COD5705:
NoSeriesLine.LOCKTABLE;
IF NoSeriesLine.FIND('+') THEN;
IF InvtSetup."Automatic Cost Posting" THEN  BEGIN
  GLEntry.LOCKTABLE;
  IF GLEntry.FIND('+') THEN;
END;
Before this code there is no SETRANGE or SETFILTER statement for the NoSeriesLine variable. So this code is always picking out the last record in the No. Series Line table. And as this table is hardly updated this statement is always finding the same record, which functionality has no relation with the no. series used in a statement somewhat further down in both codeunits:
TransShptHeader."No. Series" := InvtSetup."Posted Transfer Shpt. Nos.";
So my basic question is:
What is the use of the statement IF NoSeriesLine.FIND('+') THEN; as it will always take and - eventually - lock the last record in the No. Series Line table and thus always locking out the next proces that will execute the same codeunit?

Note
Code is from NAV 209 R2. The code is the same in 50 SP1 and in essence also the same in 2013.
Luc van Vugt, fluxxus.nl
Never stop learning
Van Vugt's dynamiXs
Dutch Dynamics Community

Comments

  • jglathejglathe Member Posts: 639
    Hi,
    lvanvugt wrote:
    So my basic question is:
    What is the use of the statement IF NoSeriesLine.FIND('+') THEN; as it will always lock the last record in the No. Series Line table and thus Always locking out the next proces that will execute the same codeunit?

    Just this. Exclusive access, ensuring that the lock actually holds true. Jörg Stryk explained it here.

    As for the sense of it, I don't know. There are more strange things in warehouse functionality, like this performance issue. Thanks for pointing it out, though.

    with best regards

    Jens
  • lvanvugtlvanvugt Member Posts: 774
    Hi Jens,

    Exactly our thoughts when coming across it. Thanx for the confirmation.
    For now we have build a workaround for this code which somehow looks like this:
    OurSetup.GET;
    CASE OurSetup."Deadlock Debug" OF
      OurSetup."Deadlock Debug"::SETRANGE:
        BEGIN
          NoSeriesLine.LOCKTABLE;
          NoSeriesLine.SETRANGE("Series Code", 'TV'); //hard coded for now to test it
          IF NoSeriesLine.FIND('+') THEN;
        END;
      OurSetup."Deadlock Debug"::ORIGINAL:
        BEGIN
          NoSeriesLine.LOCKTABLE;
          IF NoSeriesLine.FIND('+') THEN;
        END;
    END;
    IF InvtSetup."Automatic Cost Posting" THEN  BEGIN
      GLEntry.LOCKTABLE;
      IF GLEntry.FIND('+') THEN;
    END;
    
    The Deadlock Debug field in OurSetup is an option field with OptionString=ORIGINAL,SETRANGE,NOLOCK.
    Currently we are using NOLOCK and it seems to work much better then ORIGINAL. We haven't tested SETRANGE yet in production as there was no need for it.

    BTW: still interested on other's opinions on this matter.
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
Sign In or Register to comment.