Record Locking in RPGLE

1780 pts.
Tags:
AS/400
RPG Record Locks
RPGLE
I'm using embedded SQL to delete (clear) all records in a file. I do not want more than 1 person in this file. So when the user executes the program it runs the SQL and clears the records in the file. Now I want to do some file/record checking logic to see if the file is locked to another job. Then send user a message saying its not available. ( I know how do do that part) How can I do check that the file is locked in RPGLE. [strong][em]I know I can do it in CL and I don't want to do it that way.[/em][/strong]  Any ideas.. Thanks

Software/Hardware used:
RPGLE AS400

Answer Wiki

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

First off, The way I read your question tells me you want to Clear a File and after that check to see who is using it. Is that correct?
If so, could you explain why.
I would think you would do it in the reverse order. Make sure no one is using before the clear.
Anyway, here are some options.
Prior to calling the RPG program, you can check for locks and/or ALCOBJ.
Or, Once in the RPG program, you can call a CL program or procedure that would check for locks and return a parm. The CL program could create a file or Data Queue that could be used by the calling program to send message to users.

Discuss This Question: 9  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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • RonKoontz
    I want to check to see if its locked before I clear it. Otherwise it takes forever for it to time out and give me the error back.
    1,780 pointsBadges:
    report
  • RonKoontz
    and ONCE again.. I do not want to use a CL program. I know how to do it that way. That is why I said that in my original post. NO CL solutions please.
    1,780 pointsBadges:
    report
  • RonKoontz
    No using data areas either
    1,780 pointsBadges:
    report
  • philpl1jb
    Lucy, why do you always pull the football away when Charlie Brown is about to kick it? An rpg-sql program could detect record locks and lock the records if: - the file is journalled - sql commitment control is set to something like *all - it issued a command like Select * from myfile for update. I doubt that this would be much faster than your delete command. If successful, you could then issue a delete command hoping that no new records were added and locked in the interim. Of course, the select for update would wait on a locked record for the record wait time, just as your delete did. You could change the record wait time one of two ways using mum-mum commands. Nothing I've said would fulfill your original request regarding file locking, file locking can only be detected in RPG if records are currently locked or it's an exclusive lock. Of course, the rpg program could use an API to issue an mum-mum command to determine the actual file lock state or better yet to lock the file. Got though it without saying those dirty words. Phil
    50,415 pointsBadges:
    report
  • Whatis23
    Look into the Retrieve Job Information (QUSRJOBI) API, format JOBI0200, 'Active job status'.
    5,665 pointsBadges:
    report
  • TomLiotta
    If you want to check for locks, call the List Object Locks (QWCLOBJL) API and process the list. Personally, I rarely see any point to coding a bunch of instructions that replace single or few instructions. E.g., I'll almost always code a CL proc before resorting to QCAPCMD (or even QCMDEXC). Various forms of assembler are left behind for similar reasons. Now, checking for locks isn't quite the same as establishing locks. For checking, it's not easy to beat QWCLOBJL in any language. Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    API's wonderful idea. Retrieve Record Locks (QDBRRCDL) API - I think this requires a record number what about The QWCRLCKI API requires thorough research to code. This is partially because it is capable of returning many different types of lock information. Depending on the input parameters, it can return any of the following: Object and file level locks File member locks File record locks thanks to Charlie Brown and tomLotte
    50,415 pointsBadges:
    report
  • RonKoontz
    Bingo!!!! I think the API will work just fine. Most of the time I will use a CL. I just didn't want to this time. I'm always looking for new ways of doing things. It keeps us all thinking... Thanks to all...
    1,780 pointsBadges:
    report
  • TomLiotta
    Added note... the List Open Files (QDMLOPNF) API might be useful as well. Once you determine if a job has a lock on a file, it might also be useful to know if the file is actually open. Remote SQL requests can cause server jobs to obtain and to retain locks on files. The locks may stick until the server job reaches its re-use limit even if that file is never used again. Tom
    125,585 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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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

Following