Nested loops + MarkedOnly

abartonicekabartonicek Member Posts: 162
edited 2006-01-26 in Navision Attain
Because of some circumstances I have to use marking as ONLY solution for my filtering so it comes down to this:
...
SL.MARKEDONLY;
  SL.FIND('-');
  REPEAT
    Flag := TRUE;
    SL1.FIND('-');
    REPEAT
      IF SL1."Document No." <> SL."Document No." THEN
        SL1.MARK(FALSE)
      ELSE
        SL1.MARK(TRUE);

      IF SL1.MARK THEN
        Flag := FALSE;
    
      IF SL1.NEXT = 0 THEN
        Flag := FALSE;

    UNTIL Flag;
  UNTIL SL.NEXT = 0;
SL1.MARKEDONLY;
...
SL and SL1 are record variables of the same subtype.
SL has SETSELECTIONFILTER set on it.
SL1 is a group of marked sales lines and I must select all the lines where "Document No." are the same!
This "selecting" is actually unmarking the marked lines which do not meet required conditions.

Speed would be acceptable IF IT WOULD WORK THIS WAY.
When I run this piece of code Navision freezes :oops:
What did I do wrong (beside poor solution design :oops: )
Better to be critical then self-critical :)

Answers

  • krikikriki Member, Moderator Posts: 9,112
    I think your solution is a little too complicated.

    Better try something like this (didn't test it though)
    // tmpSL is a temptable
    
    // put all SL1 marked records in a temptable
    SL1.MARKEDONLY(TRUE);
    IF SL1.FIND('-') THEN 
      REPEAT
        tmpSL := SL1;
        tmpSL.INSERT(FALSE);
      UNTIL SL1.NEXT = 0;
    
    // now delete all records I want TO KEEP from the temptable 
    SL.MARKEDONLY(TRUE); 
    SL.FIND('-'); 
    REPEAT
      tmpSL.RESET;
      tmpSL.SETRANGE("Document No.",SL"Document No.");
      tmpSL.DELETEALL(FALSE);
    UNTIL SL.NEXT = 0; 
    
    // all the records still in the temptable, I do NOT want in SL1
    tmpSL.RESET;
    IF tmpSL.FIND('-') THEN
      REPEAT
        SL1.GET(tmpSL-key-fields);
        SL1.MARK(FALSE);
      UNTIL tmpSL.NEXT = 0;
    
    // now in SL1 you have the records you want
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • kinekine Member Posts: 12,562
    Why it is not working? Because:

    You are filtering for MarkedOnly.
    You change mark on some record to false.
    Where will go the NEXT command? You changed "field" which is used for filtering in the loop... it is common problem...

    The next will be lost in the loop if you do that.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • abartonicekabartonicek Member Posts: 162
    It slipped my mind O:)
    I was soooo occupied with that nested loop #-o
    Thanks, both of you!
    Better to be critical then self-critical :)
  • DenSterDenSter Member Posts: 8,307
    It would probably go much faster if you used a temporary table and insert the ones from the regular table into it, and then you use the temp table to display.
  • abartonicekabartonicek Member Posts: 162
    Sorry for not saying this before but I solved the problem. It was simple after my mind started to work ](*,)
    I added one Boolean flowfield to the table which checks all my conditions and now I'm filtering by that field. I don't know how I didn't figured that out before :?:
    Thanks for your help, guys :wink:
    Better to be critical then self-critical :)
Sign In or Register to comment.