I'm experiencing a lock on a member in a file. The message I receive is,
"Member (file name) already in use." The lock is apparently created
by a RPG program .
I cannot find any way to release the lock. I've tried DLCOBJ for all levels
(*SHRRD/*EXCL/etc.) for both the physical and the logical file involved.
Nothing seems to work -- except logging off and logging back on
If the lock is being set by the RPG program please check how the RPG pgm is returning back the control to the calling program.
If the program is just doing a RETURN and not setting on LR indicator before returning back the control then the lock would remain. You have to have a SETON LR statement before RETURN statement.
besides LR if you chain to a file when its an update file
you must release the lock prior to leaving the program or a
lock will remain.
you can chain with a no-lock
chain(n) (key1:key2) somefile
or you can use the unlock opcode on the file...
I'm here to chew bubble gum and kick @#%@#%@#%.....and I'm all outta bubble gum !
Yes I'm talking to you squirrel nuts.
yet an other question:
Are you files registered in a journal and are you working with commitment control?
A row/record locked under commitement controls can only be released by executing a Commit (for confirmation) or Rollback (for resetting).
Btw a record locked under commitment control cannot be released with the (N)-extention in RPG!
Thank you guys fior your reply for my query..
but still i didn't get the solution for that..
ReachKrishna : Krishna I am Setting ON the LR indicator.
as400Pro: I used that file in the input mode only not in the update mode..
B.Hauser : no journel is attached to that file.
It wasn't clear intially, but is the message "locked to this job" or simply "Already in use".
If it is the later then this means that some other job, process or user is using this member. You can find out what is locking the member by using WRKOBJLCK for the file in question.
If it is the former then either your current program or a called/calling program is holding a lock. A combination of the things mentioned in the other responses should help you resolve this.
i got the later one. that is 'Already in use'.
i checked with WRKOBJLCK. the PF is being locked by RPG program. with lock status *SHRRD. and my RPG only Reads the physical does not updates.
what i am trying to do is..
in one session i am running a RPG program.
in another session i am trying to clear the physicial file using CLRPFM command which was used for input in the above RPG program.
I got the following error message.
Message ID . . . . . . : CPF3156
Date sent . . . . . . : 07/09/06 Time sent . . . . . . : 14:36:57
Message . . . . : File BFD in library MUKUNDAN in use.
Cause . . . . . : Either the initialize physical file member (INZPFM)
command or the clear physical file (CLRPFM) command failed because the file
is being processed in another job or thread within your job.
Recovery . . . : Allocate the file (ALCOBJ command) and then try either the
INZPFM or the CLRPFM command again.
You cannot clear a File in one job while it is being accessed by another job, regardless of whether that file is open for input or update.
CLRPFM needs an "Exclusive" lock to work. Therefore you cannot do this.
You would need to end the job on the first session before the CLRPFM would work.
Thank you Mike..
is there is any way to read a file without locking it, in RPG?
The problem here is that you need to distinguish between "File Locking" and "Record Locking"
When a program starts that uses a file in RPG a basic Lock is applied to the file in all cases. This basically tells the system that this program is using the file, doesn't matter if it's input or update mode.
Declaring the file as input or update, tells the program how to handle "record" level locking. i.e. the record will not be locked in Input mode but will be locked in Update mode.
The question I would ask is "Why would you need a program to Clear the file while users or another program is viewing it?"
If the Clearing of the file is part of an End of Day process then some sort of check on open jobs and a way of closing them first would be required.
You can clear a file that is in use, provided a record lock is not in place. You need to use SQL
DELETE FROM myfile
This will delete all records from the file, and does not require exclusive access. The SQL statement can be imbeddded in RPG or run seperately.
Total records . . . . . . . . . . . . . . : 0
Total deleted records . . . . . . . . . . : 124
But with the CLRPFM command it gets rid of the deleted records as well.
Total records . . . . . . . . . . . . . . : 0
Total deleted records . . . . . . . . . . : 0
There is a parameter on CRTPF/CHGPF that may be usable: