Discussion:
how 2 handle the file locking during program execution?
(too old to reply)
rahul
2008-10-23 07:03:45 UTC
Permalink
i have faced the same probleam many of time e.g, if my file containes
10000 records and file is locked @ 5th record during run time of
program so, how i can handle such type of situation.
Jonathan Bailey
2008-10-23 09:29:55 UTC
Permalink
Post by rahul
i 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.
Mike
2008-10-23 12:51:35 UTC
Permalink
Post by rahul
i 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
Karl Hanson
2008-10-23 12:56:52 UTC
Permalink
Post by Jonathan Bailey
Post by rahul
i 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.
<snip>

As Jonathan said, your options may depend on the program or interface
being used to access records. To determine the source of the conflicting
lock, you might try checking the job log for message CPF5027:
Record &6 in use by job &9.
If this message is present, the job name identifies the lock holder. You
may be able to find the application, and possibly make a change to
release the lock sooner. Note that the WRKJOB CL command option 12, then
F10, shows record locks held by the job.

Also, if the conflicting record lock is not held indefinitely, but only
slightly longer than your program currently waits (lock time-out), the
WAITRCD parameter of the OVRDBF CL command could possibly be used to
wait longer, until the other job releases its record lock.

--
Karl Hanson

Loading...