MARK won"t mark

asmilie2b3asmilie2b3 Member Posts: 39
Hello all,

I am trying to use MARK to mark some entries and then only display them. I haven't used MARK much previously but it would really help now.

I have on a form, the below code in a function which is called from OnAfterGetRecord.
PurchCrMemoHeader.RESET;
PostedPurchInvoice.SETRANGE("ACW Service Order No.", "No.");
IF PostedPurchInvoice.FINDSET THEN REPEAT
  PurchCrMemoHeader.SETRANGE("Adjustment Applies-to",PostedPurchInvoice."No.");
  LinkedPostedPCM += PurchCrMemoHeader.COUNT;
  IF PurchCrMemoHeader.FINDFIRST THEN REPEAT
    PurchCrMemoHeader.MARK(TRUE);
  UNTIL PurchCrMemoHeader.NEXT = 0;
UNTIL PurchCrMemoHeader.NEXT = 0;
PurchCrMemoHeader.SETRANGE("Adjustment Applies-to");

Then, I have a field which for the ondrilldown function uses the below:
PurchCrMemoHeader.MARKEDONLY(TRUE);
FORM.RUN(FORM::"Posted Purchase Credit Memos",PurchCrMemoHeader);

I should only see a few entries, but the MARKEDONLY filter is not applied. Can MARKEDONLY not be used when doing a FORM.RUN?
Any thoughts appreciated.

Answers

  • krikikriki Member, Moderator Posts: 9,112
    It should work. I just tried it and the form shows the markedonly records. Probably something is wrong with your loop.

    But on SQL, it is best to avoid MARK because it is a performance killer. It is best to save the records in a temptable and then run the form with the temptable.
    PurchCrMemoHeaderTemp.RESET; // this is a temptable
    PurchCrMemoHeaderTemp.DELETEALL(FALSE);
    
    PostedPurchInvoice.RESET; // to be sure you don't have other filters on it
    IF PostedPurchInvoice.SETCURRENTKEY("ACW Service Order No.") THEN ; // try to use a good index for faster searching the records ; the IF THEN avoids an error in case no key exists.
    PostedPurchInvoice.SETRANGE("ACW Service Order No.", "No.");
    IF PostedPurchInvoice.FINDSET THEN
      REPEAT
        PurchCrMemoHeader.RESET;
        IF PurchCrMemoHeader.SETCURRENTKEY("Adjustment Applies-to") THEN ; // try to use a good index for faster searching the records
        PurchCrMemoHeader.SETRANGE("Adjustment Applies-to",PostedPurchInvoice."No.");
        // LinkedPostedPCM += PurchCrMemoHeader.COUNT; // you scan the records twice: once for the COUNT and once for the FINDSET
        IF PurchCrMemoHeader.FINDSET THEN // for a loop, NEVER use FINDFIRST, but FINDSET (or FIND('-' / '+')
          REPEAT
            // not needed anymore PurchCrMemoHeader.MARK(TRUE);
            LinkedPostedPCM += 1; // to avoid the COUNT
            PurchCrMemoHeaderTemp := PurchCrMemoHeader; //NEW LINE
            PurchCrMemoHeaderTemp.INSERT(FALSE); //NEW LINE
          UNTIL PurchCrMemoHeader.NEXT = 0;
      UNTIL PurchCrMemoHeader.NEXT = 0;
    // PurchCrMemoHeader.SETRANGE("Adjustment Applies-to"); not really needed. It is best to always use RESET-SETCURRENTKEY-SETRANGE/SETFILTER, so you always have all together and can be sure you don't have any filters for other parts of the program.
    
    FORM.RUN(FORM::"Posted Purchase Credit Memos",PurchCrMemoHeaderTemp);
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • asmilie2b3asmilie2b3 Member Posts: 39
    Hello Alain,

    Many thanks for your detailed answer. It was my lucky day. I had not known MARK was not good for SQL performance. Point noted. And for several reasons a temptable sounds much better. Easier to debug, more flexibility with sorting etc. I will go with that.

    Also thanks for pointing out the anomalies in my code. I was always under the impression that since FINDFIRST was implemented it was better for performance than FIND('+'), but now I see with a loop that is not the case. Also a very elegant method with the IF SETCURRENTKEY(....) THEN.

    Much food for thought today, I am humbled. :)

    Bruce Anderson
  • krikikriki Member, Moderator Posts: 9,112
    Check also this : http://www.mibuso.com/howtoinfo.asp?FileID=22.
    Be careful for an indigestion :lol:
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • asmilie2b3asmilie2b3 Member Posts: 39
    I read that post a couple of years ago, and you know now re-reading it this time it is starting to make sense. Thanks for sharing.
  • Borrachon2013Borrachon2013 Member Posts: 5
    Thanks for the tip... MARK and MARKEDONLY doesnot work, I think it is because ther MARKS dissappear when a form is openend or closed.

    But a temporary table... brilliant.

    Raymond
    Simple is simply the best
Sign In or Register to comment.