5 pts.
 Who is using an AS/400 file
RPG
I want to clear a file in RPG, but find that it is in use. How can I determine, programatically, what user(s) is locking the file?

Software/Hardware used:
ASKED: September 23, 2008  9:52 PM
UPDATED: August 1, 2010  5:01 AM

Answer Wiki:
this is kind of complicated but... before clearing the file in rpg, have your rpg program call a cl program that does this command WRKOBJLCK OBJ(library / filename) OBJTYPE(*FILE) output(*print) , then copy the spoolfile to a physical file. cpysplf. and have your rpg program read the physical file to see if there are locks and what the locking jobs are. If necessary, you can then call a cl program to end the locking jobs, disable the user profiles, and reenable them after your program is finished. I used to do that in a backup job stream.
Last Wiki Answer Submitted:  September 24, 2008  3:52 pm  by  philpl1jb   44,220 pts.
All Answer Wiki Contributors:  philpl1jb   44,220 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

You can clear a file that is in use, if you wan to. Instead if CLRPFM use SQL
DELETE FROM mylib/myfile
It can be run thru RUNSQLSTM or embedded in a RPG pgm

 3,115 pts.

 

 

If the file you triing to clear is not a User Controlled (UC) file, you are allocated to it.
Make it a (UC) file and before you open it, use QCMDEXC to clear it (CLRPFM). Then open it.

 20 pts.

 

If the file is in use by someone else, it seems odd to be trying to clear it. That would obviously have serious effects on someone else’s job. Perhaps a review of the application design is in order.

However, the List Object Locks (QWCLOBJL) API will list all jobs that currently have any kinds of locks on a file member. There might be multiple jobs.

Tom

 108,360 pts.