Options

Limiting database reads when processing lots of records

krikikriki Member, Moderator Posts: 9,096
edited 2006-03-08 in NAV Tips & Tricks
E.g. you are scanning T32:"Item Ledger Entry" and for each record, you read the T27:"Item"-table. So the number of reads you do on the database is double the number of "Item Ledger Entry"-records. This can be limited a lot.
GetItem(IcodItemNo : Code[20];VAR OrecItem : Record Item)
// GetItem
// Gets the item in "tmpItem"
// PARAMETERS:
//   IcodItemNo : item no to get
//   OrecItem : record in which the item will be put

IF tmpitem."No." <> IcodItemNo then
  IF not tmpitem.get(IcodItemNo) THEN begin
    recItem.get(IcodItemNo);
    tmpitem := recItem;
    tmpitem.insert(FALSE);
  end;

OrecItem := tmpitem;
-"tmpItem" is a global temptable on T27:"Item".
-"recItem" is a global table on T27:"Item".

With this function, each item-record is read only once from the DB. For the rest it is kept in memory until the end of your run.

Use :
recItemLedgerEntry.RESET;
recItemLedgerEntry.SETCURRENTKEY+SETRANGE+SETFILTER;
IF recItemLedgerEntry.FIND('-') THEN
  REPEAT
    GetItem(recItemLedgerEntry."Item No.",LrecItem); //LrecItem is a local variable 
    ...
  UNTIL recItemLedgerEntry.NEXT = 0;
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.