failed lookup - need to close?
Kenneth Brody
kenbrody at bestweb.net
Fri Jul 1 11:36:03 PDT 2005
Quoting Larry Dannenberg (Fri, 1 Jul 2005 14:12:48 -0400):
> In lines 4 and 8 below, if the lookup fails, the file is closed. A
> colleague I work with mentioned that it is not necessary to "close"
> the file if the lookup fails because the file was never opened.
If the file were never opened, how did filePro know that it couldn't
find the record you looked for?
> Is it good programming technique to directly "close" the file or is it
> an unnecessary step?
[...]
It's an unnecessary step. Closing the file means that the next time
you do a lookup to that file, filePro must again go through all of the
overhead of opening the file. (ie: reading the map, scanning for
key/data/index files, allocating buffers, and so on.) Considering that
the first thing your processing does after closing the file is execute
a lookup-free to the same file, all you are doing is slowing down your
system.
Second, since the lookup-free has the "-e" (report error in failure)
flag, there is no need to check for failure afterwards.
Finally, since you do the exact same code whether you succeed in the
lookup, or get a new record with the lookup free, you can clean up
your code somewhat by using:
Then: lookup imp = IMpeople k = (sv{"C") i = E -nx
If: not imp
Then: lookup imp = IMpeople r = free -e
Then: imp(1)=2;imp(2)=3;imp(3)="C";imp(4)=17;imp(5)=16;imp(6)=sv
Then: write imp
Then: return
--
KenBrody at BestWeb dot net spamtrap: <g8ymh8uf001 at sneakemail.com>
http://www.hvcomputer.com
http://www.fileProPlus.com
More information about the Filepro-list
mailing list