Select Master if tagno("codes")=0 index on codes tag codes endif if tagno("pqty")=0 index on pqty tag pqty endif Replace All pqty With qty && index could hurt here - measure effect of 2. index! lnLenMaster = len(codes) .... ** for loop to scroll on sales.dbf select sales for && scan if possible cur_code = padr(codes, m.lnLenMaster) Select purchase Do While endloop>0 && move to scan if possible Select Master Locate For codes=m.cur_code And pqty>0 If Found() .... endfor && scan