20 pts.
 OCL to CL conversion
In OCL you can check a file for activity by using the an If Active command.  Is there something similar in CL programming?



Software/Hardware used:
iseries running V6R1
ASKED: May 19, 2011  5:06 PM
UPDATED: May 20, 2011  11:58 PM

Answer Wiki:
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  CharlieBrowne   32,805 pts.
All Answer Wiki Contributors:  CharlieBrowne   32,805 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


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


 

You can use ALCOBJ with *EXCL to ensure no one else is using the file.

 32,805 pts.

 

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:

ALCOBJ (<file ID> *EXCL)
MONMSG (CPF1002) ...
ALCOBJ (<file ID> *SHRxx)
DLCOBJ (<file ID> *EXCL)

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

 107,845 pts.

 

Typo — {if the file was “active” at the beginning} should be {if the file was not “active” at the beginning.}

Tom

 107,845 pts.