FUNCTION GetProductCode()
while true
  fopen dpath|"tempprod.dat" as 1       ' get next temp prod code
  fread 1 into ptval
  fclose 1
  prodcode = $cat|"/"|right("000000"|str(ptval),6)
  clear ptval                          'message "prodcode is:"&str(prodcode)
  repaint off
  vloadif(dpath|"products.vws")
  order change key "[Product_Code]"
  data find "[Product_Code]" equal prodcode options ""
  if cerror                     ' if not found then unique
    exit function       ' if not found, proceed with suggested code
  else
    UpdateProductCode()
  end if
end while
END FUNCTION 'GetProductCode()


FUNCTION UpdateProductCode()
  increment(dpath|"tempprod.dat",1)   ' increase counter
END FUNCTION ' UpdateProductCode()
