Multiple record locks in one file

Multiple record locks in one file

Post by Sam Lenno » Tue, 14 Jul 1998 04:00:00



This is an interesting one...  I haven't had to lock multiple records in the
same file and I'm not sure it can be done in one program.  If it can I'd
like to know how.

I think what you may have to do is arrange to have multiple ODP (open data
paths) to the file as I think you can have only one lock per ODP.

As for ILE, I'm not sure that will help, since (at least in RPG) I believe
you can't have recursion if there is a file specified.  Maybe COBOL is
different, but it's not one of my strong points.

Food for thought.

Sam


>I want to lock multiple records from one file at the same time.
>I'm not familar (yet) with ILE but read something about local vars and
>recursive calls.

>Is this possible or has someone a piece of code?

>Theo.

 
 
 

Multiple record locks in one file

Post by Paul Nicola » Wed, 15 Jul 1998 04:00:00


Hi Theo,

Multiple locks can only be obtained by having commintment control on as it
locks every changed record until a commit or rollback statement has been
performed.  However, switching on commintment control has other
consequences related to program design.

ILE-RPG doesn't support local vars or recursive calls in it's true nature
(so in one single source member), however similar effects can be achieved
by some tricks.  Having the possibility to code functions is a great
advantage in the new ILE-RPG coding and allows you to write things like
Eval X = MyFunction(Y:Z).

Groetjes,
Paul
______________


Quote:> I want to lock multiple records from one file at the same time.
> I'm not familar (yet) with ILE but read something about local vars and
> recursive calls.

> Is this possible or has someone a piece of code?

> Theo.

       The contents of this message express only the sender's opinion.
       This message does not necessarily reflect the policy or views of
       my employer, Merck & Co., Inc.  All responsibility for the statements
       made in this Usenet posting resides solely and completely with the
       sender.

 
 
 

Multiple record locks in one file

Post by Anton Gombk?t » Wed, 15 Jul 1998 04:00:00


Theo,

Local variables:

You can do this in procedures (or functions, which is actually the same,
difference: a function returns something), which can be in the same source
file. But that has nothing to do with files; files are always global.

The background for your locking problem: With one access path you have one
file cursor that can point to and lock a record. If you need to lock
multiple records you'll need more access paths with one file cursor each.

You can open the same file more than once to get multiple access paths (do
not share access pathsin this case!).

F FILE   UF           DISK
F FILE1 UF           DISK   RENAME(RECORD:RECORD1)
F FILE2 UF           DISK   RENAME(RECORD:RECORD2)
and so on

with some overrides before the call:

OVRDBF FILE   TOFILE(FILE) SHARE(*NO)
OVRDBF FILE1 TOFILE(FILE) SHARE(*NO)
OVRDBF FILE2 TOFILE(FILE) SHARE(*NO)
and so on

This is the same in the "old-fashioned way" as in ILE. It would be the same
if you call sub-programs. The point is the number of access paths = file
cursors.

Of course there are limitations. If you have to lock 5 records or so and
this number will not grow in the future, i would use this approach.

With a higher or a unknown number of records to lock at the very same time,
i'd think over

- Paul's suggestion with commitment control
- a logical lock by means of a field, saying "this record is locked",
although this has some disadvantages if unlucky implemented.

Hope this helps

Anton Gombk?t?
AS Software
Vienna, Austria, Europe


Quote:>I want to lock multiple records from one file at the same time.
>I'm not familar (yet) with ILE but read something about local vars and
>recursive calls.

>Is this possible or has someone a piece of code?

>Theo.

 
 
 

Multiple record locks in one file

Post by Nils Kilden-Pederse » Wed, 15 Jul 1998 04:00:00


If it's all the records for a specific key you want to lock, I suggest you
lock the parent.

Nils


Quote:>I want to lock multiple records from one file at the same time.
>I'm not familar (yet) with ILE but read something about local vars and
>recursive calls.

>Is this possible or has someone a piece of code?

>Theo.

 
 
 

Multiple record locks in one file

Post by Bill Thompso » Wed, 15 Jul 1998 04:00:00


Multiple locks can obtained by using commitment control. If you use
STRCMTCTL LCKLVL(*ALL). Every record accessed for files opened under
commitment control is locked until the transaction is committed or rolled
back.

I have done this and it works fine.

--
Bill Thompson
Senior Programmer
Madison Metropolitan School District


> I want to lock multiple records from one file at the same time.
> I'm not familar (yet) with ILE but read something about local vars and
> recursive calls.

> Is this possible or has someone a piece of code?

> Theo.

 
 
 

Multiple record locks in one file

Post by boo.. » Wed, 15 Jul 1998 04:00:00


Would commitment control give you the result you need?



>If it's all the records for a specific key you want to lock, I suggest
>you lock the parent.
>Nils

>want to lock multiple records from one file at the same time. >I'm not
>familar (yet) with ILE but read something about local vars and >recursive
>calls.

>>Is this possible or has someone a piece of code?

>>Theo.

--
-----------------------------------------------------------

Booth Martin
-----------------------------------------------------------