If you mean, does it have records, then use RTVMBRD command
If you mean is someone using the file, you can use WRKOBJLCK command
*
Let me know if you need more clarification
WRKOBJLCK is great but how do you use that within a CL program to determine if you can say do a CLRPFM command?
Last Wiki Answer Submitted: May 19, 2011 6:22 pm by CharlieBrowne32,805 pts.
All Answer Wiki Contributors: CharlieBrowne32,805 pts.
If you live outside the United States, by submitting your email address you consent to having your personal data transferred to and processed in the United States.
ALCOBJ can give an indication if the file is “in use”. But keep in mind that if the command succeeds, you should probably immediately deallocate the file.
That is, I try to allocate exclusively. I would have a MONMSG after the first ALCOBJ to catch a failure of exclusive access; the action to take would depend on what needed to be done for that program.
If the first ALCOBJ succeeded, the second ALCOBJ would set whatever access level that I actually wanted. Once that was set, I would deallocate the initial exclusive lock.
The final result is a shared lock that would only be possible if the file was “active” at the beginning.
All of that might need clarification depending on what is meant by “active” and what the purpose of testing for “active” is in the first place. Usually the use of that S/36 OCL feature is inappropriate in native AS/400 procedures. It most often means that a process should be redesigned to work according to how this system can do things.
For example, it might be that there is a desire to clear a file; but that it shouldn’t be done while the file is “active”. Well, if the file is “active” and you try to run a CLRPFM command against it, the CLRPFM command itself will report back that the file is “active”. In such a case, there’s no point to running a specific test ahead of time.
You can use ALCOBJ with *EXCL to ensure no one else is using the file.
ALCOBJ can give an indication if the file is “in use”. But keep in mind that if the command succeeds, you should probably immediately deallocate the file.
What I usually do is a sequence like this:
Then the programming continues.
That is, I try to allocate exclusively. I would have a MONMSG after the first ALCOBJ to catch a failure of exclusive access; the action to take would depend on what needed to be done for that program.
If the first ALCOBJ succeeded, the second ALCOBJ would set whatever access level that I actually wanted. Once that was set, I would deallocate the initial exclusive lock.
The final result is a shared lock that would only be possible if the file was “active” at the beginning.
All of that might need clarification depending on what is meant by “active” and what the purpose of testing for “active” is in the first place. Usually the use of that S/36 OCL feature is inappropriate in native AS/400 procedures. It most often means that a process should be redesigned to work according to how this system can do things.
For example, it might be that there is a desire to clear a file; but that it shouldn’t be done while the file is “active”. Well, if the file is “active” and you try to run a CLRPFM command against it, the CLRPFM command itself will report back that the file is “active”. In such a case, there’s no point to running a specific test ahead of time.
Tom
Typo — {if the file was “active” at the beginning} should be {if the file was not “active” at the beginning.}
Tom