/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/,FALSE);
NoOfOrder:=0;
IF OrderAmount=0 THEN
REPEAT
NoOfOrder:=NoOfOrder + 1;
IF NoOfOrder=2 THEN BEGIN
END;
UNTIL (/Sales Header/.NEXT=-1) OR (NoOfOrder=2);