Who is using an AS/400 file

5 pts.
Tags:
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?

Answer Wiki

Thanks. We'll let you know when a new response is added.

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.

Discuss This Question: 11  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • graybeard52
    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 pointsBadges:
    report
  • graybeard52
    Also, check out PRCOBJLCK command at http://systeminetwork.com/article/easily-respond-object-and-record-lock-events
    3,115 pointsBadges:
    report
  • Andrewsdad
    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.
    30 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • TheRealRaven
    What is meant by "[I] find that it is in use"? How do you "find" that? Is there an error when you try to run some part of your code?

    "Programmatically" with RPG, you should be able to pull related error info out of the PSDS.

    How are you intending to "clear" a file with RPG?
    29,400 pointsBadges:
    report
  • ToddN2000
    This is an old thread but over the years there has been some code enhancements that some people may be unaware of.For a lot of my career I worked with with legacy code or maintained some poorly written applications. One of the thing I found was the cause of some of the locks on a file is one simple op-code CHAIN. A lot of older programs would chain to a file for verification of the key.  An example is a program may chain to your order file for an inquiry but has no plans to update the file. It will still lock the record in the file unless you use the CHAIN(N) op-code to not lock the record. This frees it up and you would be able to use the file fore other purposes.
    117,375 pointsBadges:
    report
  • TheRealRaven
    I get ITKE notifications through RSS or mailing list (mailing, I think), and notices regularly come through when someone makes any change. Edits to the question or title, changes to 'Answers', who knows what. Apparently, it seems to be just a moderator's removal of a spam/junk.

    But the notice makes it seem like a "new" thread, and seeing the old date doesn't happen. Just one of the little irritations.

    As for CHAIN, I've never understood why someone would use CHAIN for just verification when SETLL works better -- no record I/O happens and no need to be concerned over locks. Only the index entry is checked.
    29,400 pointsBadges:
    report
  • WoodEngineer
    This should provide the info you want:
    WRKOBJLCK OBJ(yourfile) OBJTYPE(*FILE) MBR(*FIRST)     
    Mbr(*first) typically provides more info than the default of Mbr(*none)
    8,160 pointsBadges:
    report
  • TheRealRaven
    But "programmatically" kind of implies a need to do it without screen I/O. The List Object Locks (QWCLOBJL) API may be better in that case.
    29,400 pointsBadges:
    report
  • WoodEngineer
    I agree with TheRealRaven if you need to do this programmatically.  There is a little overhead when using an API but they execute very quickly.  It is worth taking the time to understand how to program API's since IBM has provided to many functions when can be used in a program via these tools.
    Check out the example here.
    8,160 pointsBadges:
    report
  • WoodEngineer
    Here is a good example of using the API TheRealRaven mentioned.  It is worth the time to learn now to program API's.  They provide so much functionality.  
    8,160 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: