Performance Issues: FindFirst and Findset

fazlehasanfazlehasan Member Posts: 70
Hi,

We are using NAV 5.0 SP1 and SQL 2012.

I have a scenerio where I have to deal with the First Record in a record set differently than the rest of the records in the recordset;

I know using repeat..until inside FIRSTFIRST is not recommended.
So I was wondering between (A) and (B) which would be better performing:

(A)
IF FINDSET then begin
if FirstRecordFlagVar then begin
Do Something with the First record in the recordset;
end
else begin
repeat
Do Something with other records in the recordset;
until NEXT=0;
end;
end;

(B)

IF FINDFIRST then begin
Do Something with the First record in the recordset;
While (NEXT<>0) Do begin
Do Something with other records in the recordset;
end;
end;

(I am losing the indentation in the preview, sorry for that)
(It's second time I am posting it, last time my post was lost to oblivion, when I mistakenly did not put the Subject Line, may be webmaster can take care of it)

Thanks
Fazle

Comments

  • MBergerMBerger Member Posts: 413
    i would go option B, but altered :
    IF FINDSET then begin
      Do Something with the First record in the recordset;
      While (NEXT<>0) Do begin
        Do Something with other records in the recordset;
      end;
    end;
    
  • fazlehasanfazlehasan Member Posts: 70
    Thanks @MBerger.

    But in C/Side Reference Guide they are saying:
    You should only use this(FINDSET) function when you explicitly want to loop through a recordset. You should ONLY use this function in combination with REPEAT .. UNTIL

    So WHILE Loop can be used inside FINDSET?

    Thanks
  • ReinhardReinhard Member Posts: 249
    Fazle,
    Yeah, you can do that. Only the "NEXT" actually generates a server call.

    Also use the [ code ] tags like MBerger has done to keep the formatting on your code.

    - Reinhard
  • bbrownbbrown Member Posts: 3,268
    I would likely go with something like this. Also the size of the record set and what I am doing would determine if I use FINDSET or FIND('-') and the parameters on FINDSET.
    RecordNo := 0;
    // set keys and filters
    IF FINDSET THEN
      REPEAT
        RecordNo += 1;
        IF RecordNo = 1 THEN BEGIN
          // code for first record
        END  ELSE BEGIN
          // code for other records
        END;
      UNTIL NEXT = 0;
    
    
    
    There are no bugs - only undocumented features.
  • fazlehasanfazlehasan Member Posts: 70
    Thanks @bbrown,@Reinherd,@Mberger for your inputs.
    =D> =D> =D>
Sign In or Register to comment.