Tuesday 25 August 2015

Difference between FINDSET, FINDFIRST and FIND('-')

1. FINDSET :


  • Retrieves set of records.
  • Transaction begins with FINDSET Command. 

2. FINDFIRST : 
  • It will retrieve the first record
  • Retrieves only 1 record, the last one within filter, sorted accordingly.
  • Transactions begins when a call to update the database. (Insert, modify, delete).
  1. Opens the connection with database
  2. fetches the record from database
  3. closes the connection
Example:


IF EmployeeVar.FINDFIRST THEN

      MESSAGE('employee no. %1',EmployeeVar."Employee No.");

Since we are not repeating the process its better to use FINDFIRST if you're fetching only one time from the database.

3. FIND('-') :
  • It will also retrieve the first record
  • Retrieves only 1 record, the last one within filter, sorted accordingly.
  • Transactions begins when a call to update the database. (Insert, modify, delete).
  1. Opens the connection with database
  2. fetches the record from database
  3. doesn't close the connection until the condition is false.


IF EmployeeVar.FIND('-') THEN
REPEAT
      MESSAGE('employee no. %1',EmployeeVar."Employee No.");
 UNTIL EmployeeVar.NEXT=0;


Since we are repeating the process its better to use FIND('-'), it will work fine even if we use FINDFIRST but each time it retrieves the record it opens the connection and before fetching next record it closes the connection. Which reduces performance. 

So, it better to use FIND('-) for repeated retrieval of record. 

1 comment: