Options

How can I find a minimum Value in a Field

AlexEAlexE Member Posts: 8
My Problem:
I should find the smallest Value in a tablefield. How can I do this in Navision Programming Language?

Thanks for your answer.

Comments

  • Options
    HalMdyHalMdy Member Posts: 429
    First, define a key on the field.

    Then :

    Table.SETCURRENTKEY(newKey);
    Table.FIND('-');

    You are on the record with the smallest value ...

    That's works if the field is not a flowfield, of course ...
  • Options
    krikikriki Member, Moderator Posts: 9,090
    If you need the value fast, without searching the whole DB, the method of HalMdy is ok.
    But if you don't need the value so fast, it is better to avoid creating keys for the mimimum thing, because to many keys can lead to performance issues.

    You might also try :
    recTable.RESET;
    IF recTable.FIND('-') THEN BEGIN
      xxxSmallestValue := recTable."Some Field";
      REPEAT
        IF xxxSmallestValue > recTable."Some Field" THEN
          xxxSmallestValue := recTable."Some Field";
      UNTIL recTable.NEXT = 0;
    END;
    

    This will be slow in finding the smallest value, but writing in the table will not be slowed down. (Every key in a table slows down the writing to the table)
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    KowaKowa Member Posts: 918
    If you do not want to create a new key :
    You can also create a temporary table with one field ( any free Table ID in the customer range 50000..99999 is possible , temporary tables are not checked by the licence), copy the field values to this table
    ( use "If insert then;" to avoid insert errors for double values)
    and then do a "Find('-')" on the temporary table.
    Kai Kowalewski
Sign In or Register to comment.