Sunday, May 4, 2008

Check IFS object existence:

The need of objects that exist on the IFS increases daily. Using CHKOBJ to determine the existence of an object is limited to HFS objects, and the ability to use that command on the IFS is non-existent.

The excerpt below is a nice little program, which is limited to a 30 alpha string in this example that uses the CHKIN and CHKOUT commands to determine the existence of an object. If the CHKOUT command is successful, then the object must be checked back in via the CHKIN to prevent object locks.
Code
PGM PARM(&STMF &CODE)

DCL VAR(&STMF) TYPE(*CHAR) LEN(30)

DCL VAR(&CODE) TYPE(*CHAR) LEN(1)

CHKOUT OBJ(&STMF)
MONMSG MSGID(CPFA0A9) EXEC(CHGVAR VAR(&CODE) +
VALUE('0')) /* NOT FOUND */
MONMSG MSGID(CPF0000) EXEC(DO) /* ANY OTHER ERROR +
(IN USE) */
CHGVAR VAR(&CODE) VALUE('1') /* IT ALREADY EXISTS */
CHKIN OBJ(&STMF) /* RELEASE USE */
MONMSG MSGID(CPF0000)
ENDDO
ENDPGM

No comments: