The CHKIN command can be helpful, but it also “checks in” the object. You can use CHKOUT followed by CHKIN when it succeeds in checking the object out.
For a long term viable solution, use the access() API. Here’s a trivial example:
dcl &fname *char 512
dcl &amode *int 4
dcl &F_OK *int 4 value( 0 )
dcl &W_OK *int 4 value( 2 )
dcl &x00 *char 1 value( x'00' )
dcl &rc *int 4
/* chgvar &amode &F_OK */
chgvar &amode &W_OK
chgvar &fname ( +
'/home/MyHome/p.txt' *cat +
callprc 'access' ( +
( &amode *byval ) +
rtnval( &rc )
/* Note: &rc *eq x'00000000'=0 on success; x'FFFFFFFF'=-1 on fail... */
This checks for ‘W’rite access capability to a streamfile named /home/MyHome/p.txt — the &F_OK mode value would check for simple accessibility/existence. Tests for existence assume that authority allows for at least *USE, otherwise you’re not going to see the object.
Note that the file name must be null-terminated. And note that the mode is supplied “by value” rather than by reference.
Details of access() are in with the other Unix-like APIs.
The procedure must be ILE CL (PDM member type CLLE). It could be compiled as a procedure that accepts a file name name as a parm. Or you might compile it as a *PGM and use it as the CPP for a command that returns a parm or sends *DIAG or *ESCAPE message.