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:<pre>
pgm
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 +
&x00 +
)
callprc 'access' ( +
&fname +
( &amode *byval ) +
) +
rtnval( &rc )
/* Note: &rc *eq x'00000000'=0 on success; x'FFFFFFFF'=-1 on fail... */
dmpclpgm
return
endpgm</pre>
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.
<a href="http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/apis/access.htm">Details of access()</a> 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.
Tom
Last Wiki Answer Submitted: April 20, 2010 6:34 pm by TomLiotta108,370 pts.
All Answer Wiki Contributors: TomLiotta108,370 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.
I know this is two years after the original post, but for anyone who is looking for this answer and wants to know how to check for a FOLDER or DIRECTORY and not a document, this simple logic works. I won’t say I’m proud of it….. It is more “sleight of hand than anything”.
Pass this program a path name, such as ‘/System i Users/LNapier’. The ChkOut command expects the OBJ parm to be a document, not just a directory. So, if the path is a directory, ChkOut will issue CPFA0DA.
I use the following for file, you may be able to tweak it for folders
CHKIN OBJ('ifs_path/ifs_object_name) MONMSG MSGID(CPFA0A9) EXEC(DO) RCVMSG MSGTYPE(*EXCP) GOTO CMDLBL(EXIST) ENDDO /* CPFA0A9 */ GOTO CMDLBL(NOTEXIST) EXIST: NOTEXIST:that should be
Often this requirement is followed by the need to create the folder searched for. From my archives I found this cod
PGM DCL VAR(&ARKIV) TYPE(*CHAR) LEN(132) DCL VAR(&DATE) TYPE(*CHAR) LEN(6) DCL VAR(&YEAR) TYPE(*CHAR) LEN(4) RTVJOBA DATE(&DATE) CHGVAR VAR(&YEAR) VALUE('20' *TCAT %SST(&DATE 1 2)) CHGVAR VAR(&ARKIV) VALUE('/WORK/ARKIV_' *TCAT &YEAR) CHKIN OBJ(&ARKIV) MONMSG MSGID(CPFA0A9) EXEC(MD DIR(&ARKIV)) MONMSG CPFA0DA ENDPGMI believe the code is fairly straight forward to understand.
DanF
I know this is two years after the original post, but for anyone who is looking for this answer and wants to know how to check for a FOLDER or DIRECTORY and not a document, this simple logic works. I won’t say I’m proud of it….. It is more “sleight of hand than anything”.
Pass this program a path name, such as ‘/System i Users/LNapier’. The ChkOut command expects the OBJ parm to be a document, not just a directory. So, if the path is a directory, ChkOut will issue CPFA0DA.
Pgm (&In$Path &Out$IsDir) DCL VAR(&In$Path) TYPE(*CHAR) LEN(512) DCL VAR(&Out$IsDir) TYPE(*LGL) ChgVar &Out$IsDir '0' CHKOUT OBJ(&IN$PATH) MONMSG MSGID(CPFA0DA) EXEC(ChgVar &Out$IsDir '1') MONMSG MSGID(CPFA09C CPFA09D CPFA09E CPFA0A1 + CPFA0A3 CPFA0A7 CPFA0A9 CPFA0AA CPFA0AB + CPFA0AD CPFA0B2 CPFA0BF CPFA1C5) EndPgm