How to find top five order of customer in nav

can you please check my code where i am wrong

“Sales Header”.SETCURRENTKEY(“Document Date”,“Document Type”);
“Sales Header”.SETRANGE(“Document Type”,“Sales Header”.“Document Type”::Order);
“Sales Header”.CALCFIELDS(Amount);
“Sales Header”.SETFILTER(Amount,‘<>0’);
“Sales Header”.SETASCENDING(“Document Date”,TRUE);
i:=0;
“Sales Header”.“No.”:=“No.”;
IF (NoOfOrder=0) OR (i<NoOfOrder) THEN BEGIN
i:=i+1
END ELSE BEGIN
IF “Sales Header”.FIND(‘+’) THEN
“Sales Header”.DELETEALL;
END;

Can you explain what you are trying to do? Also what NAV\BC version is this?

You need to retrieve a record before using CALCFIELDS. You can use AUTOCALCFIELDS to execute the CALCFEILDS when the records are retrieved.

Is “Sales Header” a temporary table? If not, the calling DELETEALL is a very bad idea.