In order to determine whether an object in a library exists, we can use the
CHKOBJ command. There is no command-line equivalent for IFS objects. Some
have suggested using spooled files. This solution uses one of the IFS
Unix-type APIs that gives direct feedback on the existence of any object.
This also works with library objects, using path naming.
Attached are command source with its processing program, as well as a test
case that executes the command.
The command will run only in programs or REXX procedures, since it returns a value. The test case command can run anywhere.
Some techniques are illustrated:
1. The access() API requires a null-terminated path name, so the CPP shows
how this can be done easily, using a variable length parameter in the command.
2. Many APIs that are most easily used in C/C++ can also be used in CLLE
programs, as this example demonstrates. The service program that contains
the API is automatically bound because of the standard binding directory
that is used for CLLE compilation.
3. The API returns an integer. It is necessary to use the %BIN() function
in the RTNVAL parameter of CALLPRC.
4. Using a command for the test case avoids the problem of garbage in the
CL path name parameter if the test case program is called from a command line.
To create objects (debug is optional):
CRTBNDCL PGM(SOMELIB/OBJEXISTS) SRCFILE(SOMELIB/QCLSRC)
REPLACE(*YES) DBGVIEW(*ALL)
CRTBNDCL PGM(SOMELIB/TSTOBJEXST) SRCFILE(SOMELIB/QCLSRC)
REPLACE(*YES) DBGVIEW(*ALL)
CRTCMD CMD(VERN/TSTOBJEXST) PGM(TSTOBJEXST) SRCFILE(SOMELIB/QCMDSRC)
PRDLIB(SOMELIB) REPLACE(*YES)
CRTCMD CMD(SOMELIB/OBJEXISTS) PGM(OBJEXISTS) SRCFILE(SOMELIB/QCMDSRC)
ALLOW(*BPGM *IPGM *BREXX *IREXX *BMOD *IMOD)
PRDLIB(SOMELIB) REPLACE(*YES)
Code
Check out the commands below:
ATT962061
ATT962062
ATT962063
ATT962064