FINDSET (Record)
Use this function to find a set of records in a table based on the current key and filter. The records can only be retrieved in ascending order.
Ok := Record.FINDSET([ForUpdate][, UpdateKey])
Ok
Data type: boolean
If you omit this optional return value, a run-time error occurs if the system cannot find a record. If you include a return value, the system assumes you will handle any errors. Ok can have these values:
If Ok is...
It means the record set was...
TRUE
Found
FALSE
Not found
Record
Data type: record
If the record was...
Then...
Found
The system returns the record in Record and sets any FlowField in the record to zero. You must update them using CALCFIELDS.
Not found
A run-time error occurs, if you omitted the return value Ok.
ForUpdate
Data type: boolean
Set this to FALSE if you don't intend to modify any records in the set.
Set this to TRUE if you want to modify some records in the set.
If you set this parameter to TRUE, a LOCKTABLE is immediately performed on the table before the records are read.
UpdateKey
Data type: boolean
This only applies if ForUpdate is set to TRUE.
If you are going to modify any field value within the current key, set this parameter to TRUE.
Comments
You should only use this function when you explicitly want to loop through a recordset. You should ONLY use this function in combination with REPEAT .. UNTIL.
Furthermore, FINDSET only supports descending loops. If you want to loop from the bottom up, you should use FIND(‘+’).
The general rules for using FINDSET are:
• FINDSET(FALSE,FALSE)- read-only. This uses no server cursors and the record set is read with a single server call.
• FINDSET(TRUE,FALSE)- is used to update non-key fields. This uses a cursor with a fetch buffer similar to FIND(‘-’).
• FINDSET(TRUE,TRUE)- is used to update key fields.
Note
This function is designed to optimize finding and updating sets. If you set any or both of the parameters to FALSE, you can still modify the records in the set but these updates will not be performed optimally.
Example
The following C/AL code examples show how to use the FINDSET function:Example 1
// Looping through a set without updating it.
SalesLine.SETFILTER("Purch. Order Line No.",'<>0');
IF SalesLine.FINDSET THEN BEGIN
REPEAT
CopyLine(SalesLine);
UNTIL SalesLine.NEXT = 0;
END;
Example 2
// Looping through a set and updating a field that is not within the current key.
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;
Example 3
// Looping through a set and updating a field that is within the current key.
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;
You could have found this by clickling "Help->C/Side Reference" on your client. You only have to type in FINDSET on the keyword line.
Fostering a homeless, abused child is the hardest yet most rewarding thing I have ever done.
You could have found this by clickling "Help->C/Side Reference" on your client. You only have to type in FINDSET on the keyword line.
I have to agree with KYDutchie here, this ( and your previous 2, very basic questions) could have been found using the helpfile. Just a little question, did you have ANY training in developing in NAV ? Because i am suspecting you didn't. If not, do the development training first.
Comments
Use this function to find a set of records in a table based on the current key and filter. The records can only be retrieved in ascending order.
Ok := Record.FINDSET([ForUpdate][, UpdateKey])
Ok
Data type: boolean
If you omit this optional return value, a run-time error occurs if the system cannot find a record. If you include a return value, the system assumes you will handle any errors. Ok can have these values:
If Ok is...
It means the record set was...
TRUE
Found
FALSE
Not found
Record
Data type: record
If the record was...
Then...
Found
The system returns the record in Record and sets any FlowField in the record to zero. You must update them using CALCFIELDS.
Not found
A run-time error occurs, if you omitted the return value Ok.
ForUpdate
Data type: boolean
Set this to FALSE if you don't intend to modify any records in the set.
Set this to TRUE if you want to modify some records in the set.
If you set this parameter to TRUE, a LOCKTABLE is immediately performed on the table before the records are read.
UpdateKey
Data type: boolean
This only applies if ForUpdate is set to TRUE.
If you are going to modify any field value within the current key, set this parameter to TRUE.
Comments
You should only use this function when you explicitly want to loop through a recordset. You should ONLY use this function in combination with REPEAT .. UNTIL.
Furthermore, FINDSET only supports descending loops. If you want to loop from the bottom up, you should use FIND(‘+’).
The general rules for using FINDSET are:
• FINDSET(FALSE,FALSE)- read-only. This uses no server cursors and the record set is read with a single server call.
• FINDSET(TRUE,FALSE)- is used to update non-key fields. This uses a cursor with a fetch buffer similar to FIND(‘-’).
• FINDSET(TRUE,TRUE)- is used to update key fields.
Note
This function is designed to optimize finding and updating sets. If you set any or both of the parameters to FALSE, you can still modify the records in the set but these updates will not be performed optimally.
Example
The following C/AL code examples show how to use the FINDSET function:Example 1
Example 2
Example 3
You could have found this by clickling "Help->C/Side Reference" on your client. You only have to type in FINDSET on the keyword line.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!