There's no REXX function to check if an object exists. But if you know the object ID of the object you can use the code below to test if an object already exists. (see also List all WPS known object IDs)
/* sample code to check if an object exists. Note that this code */
/* works for objects with object IDs only! */
/* load the SysCreateObject function */
call rxFuncAdd "SysCreateObject", "REXXUTIL", "SysCreateObject"
/* load the SysDestroyObject function */
call rxFuncAdd "SysDestroyObject", "REXXUTIL", "SysDestroyObject"
do until myInput = ""
say "Enter the ID of the object to check (RETURN to exit): "
myInput = strip( lineIn() )
if myInput <> "" then
do
objectExist = ObjectExist( myInput )
select
when objectExist = 0 then
say "The object """ || myInput || """ does not exist."
when objectExist = 1 then
say "The object """ || myInput || """ exist."
otherwise
say "Error """ || objectExist || """ executing ObjectExist!"
end /* select */
end /* if myInput <> "" then */
end /* do until myInput = "" */
exit 0
/* ------------------------------------------------------------------ */
/* function: Check if an object with a given object ID exists */
/* */
/* Usage: ObjectExist objectID */
/* */
/* where: objectID = object ID of the object to test */
/* */
/* returns: 1 - the object exist */
/* 0 - the object does not exist */
/* else */
/* error code of the SysCreateObject function */
/* */
ObjectExist: PROCEDURE
parse arg objectID
/* init the return code */
rc = 43 /* error code 43 = routine not found */
/* install a local error handler */
SIGNAL ON SYNTAX NAME ObjectExistError
/* check the parameter */
if substr( objectID, 2, 1 ) <> ":" then
if left( objectID,1 ) <> "<" & right( objectID,1 ) <> ">" then
objectID = "<" || objectID || ">"
/* try to create an object with this ID */
tempRC = SysCreateObject( "WPFolder" ,,
"TestObject" ,,
"<WP_NOWHERE>" ,,
"OBJECTID=" || objectID || ";" ,,
"FAIL" )
if tempRC = 1 then
do
/* object created, delete it */
call SysDestroyObject objectID
rc = 0 /* set return code to "Object does not exist" */
end /* if tempRC = 1 then */
else
rc = 1 /* set return code to "Object does exist" */
ObjectExistError:
RETURN rc