Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

FINDSET Function (Record)

Microsoft Dynamics Nav 2009

Finds a set of records in a table based on the current key and filter.


[Ok :=] Record.FINDSET([ForUpdate][, UpdateKey])

Parameters

Record

Type: Record

If the record is found, then the record is returned in this parameter and any FlowFields in the record are set to zero. You must update the FlowFields by using the CALCFIELDS Function (Record).

ForUpdate

Type: Boolean

Set this parameter to true if you want to modify any records in the set; otherwise, set the parameter to false.

If you set this parameter to true, then the LOCKTABLE Function (Record) is immediately run on the table before the records are read.

UpdateKey

Type: Boolean

Set this parameter to true if you want to modify any field value within the current key.

This parameter only applies if the ForUpdate parameter is true.

Type: Boolean

true if the record set was found; otherwise, false.

If you omit this optional return value and if the record cannot be found, then a run-time error occurs. If you include a return value, then you must handle any errors.

FINDSET can only retrieve records in ascending order. If you want to loop from the bottom up, then you should use FIND('+').

You should use this function only when you explicitly want to loop through a recordset. You should only use this function in combination with REPEAT..UNTIL.

The following table describes the general rules for using FINDSET.

Usage Rule

FINDSET(FALSE,FALSE)

Read-only. This uses no server cursors, and the recordset is read with a single server call.

FINDSET(TRUE,FALSE)

This is used to update non-key fields. This uses a cursor with a fetch buffer that is similar to FIND('-').

FINDSET(TRUE,TRUE)

This is used to update key fields.

This function is designed to optimize finding and updating sets. If you set any or both of the parameters to false, then you can still modify the records in the set, but these updates will not be performed optimally.

For more information about performance differences between using FINDSET and FIND('-'), see C/AL Database Functions and Performance on SQL Server.

This example shows how to use the FINDSET function to loop through a set without updating it. This example requires that you create a Record variable named SalesLine for the Sales Line table and that you have a CopyLine function.

SalesLine.SETFILTER("Purch. Order Line No.",'<>0');
IF SalesLine.FINDSET THEN BEGIN
  REPEAT
    CopyLine(SalesLine);
  UNTIL SalesLine.NEXT = 0;
END;

This example shows how to use the FINDSET function to loop through a set and update a field that is not within the current key. This example requires that you create the following variables.

Variable name Data type Subtype

SalesLine

Record

Sales Line

DocumentType

Option

 

DocumentNo

Code

 

This example assumes that you have assigned values to the DocumentType and DocumentNo variables and that you have a GetNewLocation function, which returns a value that is a Code data type.

SalesLine.SETRANGE("Document Type",DocumentType);
SalesLine.SETRANGE("Document No.",DocumentNo);
IF SalesLine.FINDSET(TRUE, FALSE) THEN BEGIN
  REPEAT
    SalesLine."Location Code" := GetNewLocation(SalesLine);
    SalesLine.MODIFY;
  UNTIL SalesLine.NEXT = 0;
END;

This example shows how to use the FINDSET function to loop through a set and update a field that is within the current key. This example requires that you create the following variables.

Variable name DataType Subtype

SalesShptLine

Record

Sales Shipment Line

SalesLine

Record

Sales Line

SalesShptLine.SETRANGE("Order No.",SalesLine."Document No.");
SalesShptLine.SETRANGE("Order Line No.",SalesLine."Line No.");
SalesShptLine.SETCURRENTKEY("Order No.","Order Line No.");
IF SalesShptLine.FINDSET(TRUE, TRUE) THEN BEGIN
  REPEAT
    SalesShptLine."Order Line No." := SalesShptLine."Order Line No." + 10000;
    SalesShptLine.MODIFY;
  UNTIL SalesShptLine.NEXT = 0;
END;
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.