Post by rahuli have faced the same probleam many of time e.g, if my file
containes
program so, how i can handle such type of situation.
What sort of a program is it you are running? If its RPG then simply
declare the file spec & code without any error handling & you will get
a message informing you of the lock & the chance to Cancel,Dump or
Retry. Then simply find the source of the lock, remove it & Retry.
Alternatively code some complex error handling something like
key reade(e) file
if %error(file)
-handle the lock situation
endif
If you are pgoramming in Cobol etc then your code will differ. If you
are coding SQL then I dont think you have any options.
In every case if you want no-one to lock any records in your file then
issue a CL command like
alcobj ((file *file *excl)) & remember to deallocate later with a
dlcobj
The alcobj command can be monitored for errors & take appropriate
action. You could replace *excl with another value to allow other jobs
to read from it but not to lock records. This will no doubt cause
errors in the jobs trying to lock records.
Jonathan.
There is another more elegant solution but it is only practical if you
are working on initial design of a new application or the problem file
is only accessed by a few programs.
The real cause of the record locking problem is when some program
reads a record for add / update or delete and then leaves it in that
state without completing the action for an extended time period. This
is usually some online program waiting for user input to a screen.
You can change all these "long wait update programs" that create the
locks so that they open the file for read only and then only when the
user requests a change they call a small update subprogram that
re-reads the record, checks that there have been no changes and then
if all is ok posts the update thus releasing the lock. This is
called "optimistic locking" and it works very well if you are careful
about the details and always use the update subprogram.
Mike Sicilian