How retrieving unique value from array in c/al?

mdsrmdsr Member Posts: 163
I want only distinct values from array as repeat until gives multiple duplicate value in array what modification need here as LotNoVar is array of 10 index.
as follows:
RecILE.RESET;
RecILE.SETRANGE(RecILE."Item No.","Delivery Challan Line"."Item No.");
RecILE.SETRANGE(RecILE."Document No.","Delivery Challan Line"."Production Order No.");
IF RecItem.FINDFIRST THEN
BEGIN
REPEAT
LotNoVar:=RecILE."Lot No.";
MESSAGE(LotNoVar);
UNTIL RecILE.NEXT=0;
END;

Best Answer

  • Jan87Jan87 Member Posts: 26
    Answer ✓
    You can sort by "Lot No." and then only write an entry when the value changes.

    Would look like that:
    lastLotNo := '';
    currIdx := 1;
    
    RecILE.RESET;
    RecILE.SETCURRENTKEY("Lot No.");
    RecILE.SETRANGE(RecILE."Item No.","Delivery Challan Line"."Item No.");
    RecILE.SETRANGE(RecILE."Document No.","Delivery Challan Line"."Production Order No.");
    IF RecItem.FINDSET(FALSE,FALSE) THEN BEGIN
      REPEAT
          IF lastLotNo <> RecILE."Lot No." THEN BEGIN
             LotNoVar[currIdx] := RecILE."Lot No.";
             lastLotNo := RecILE."Lot No.";
             currIdx += 1;
          END;
      UNTIL RecILE.NEXT=0;
    END;
    

Answers

  • Jan87Jan87 Member Posts: 26
    Answer ✓
    You can sort by "Lot No." and then only write an entry when the value changes.

    Would look like that:
    lastLotNo := '';
    currIdx := 1;
    
    RecILE.RESET;
    RecILE.SETCURRENTKEY("Lot No.");
    RecILE.SETRANGE(RecILE."Item No.","Delivery Challan Line"."Item No.");
    RecILE.SETRANGE(RecILE."Document No.","Delivery Challan Line"."Production Order No.");
    IF RecItem.FINDSET(FALSE,FALSE) THEN BEGIN
      REPEAT
          IF lastLotNo <> RecILE."Lot No." THEN BEGIN
             LotNoVar[currIdx] := RecILE."Lot No.";
             lastLotNo := RecILE."Lot No.";
             currIdx += 1;
          END;
      UNTIL RecILE.NEXT=0;
    END;
    
  • Developer101Developer101 Member Posts: 565
    good solution. No need FINDSET(FALSE,FALSE) , just FINDSET will do
    United Kingdom
Sign In or Register to comment.