In April of 2003, Vernon Hamberg submitted the tip, "Check object existence using IFS API". Vern's tip explains the steps to check object existence in the IFS using an API. There is a simpler method to discover if your file, folder or other IFS object exists in the IFS, without getting into custom commands and system API's.
A more practical method to discover if your file, folder or other IFS object exists is to use the RENAME command. This is the same old DOS or UNIX command we used in the 1980's where you can rename the object to the same name it already has.
Typically, once you have navigated down the folder path of the IFS to the actual folder using the WRKLNK command -- like WRKLNK OBJ( '/folderA/folderB' ) or in batch work -- you would be using the CHGCURDIR or the shortcut commands CHDIR or CD, and then you can rename your object to the same name.
If however, you do not "walk" down the folder path when using the Rename command, the first parm may contain the full path name. If it does, then you CANNOT use the full path name in the second parm. You will have to extract the object's name so it does not contain any slashes of the folder path.
REN OBJ('folderA/folderB/fileC') NEWOBJ('fileC')
You then get the completion message CPCA084 = Object Renamed
If it does not exist, you receive the diagnostic message of severity 40 CPFA0A9 = Object not found.
This same technique could be applied to the COPY command, however, the RENAME works for both files and folders, which is why I prefer using it.
- If requirements are simple, an easy way to check existence is the CHKIN command. CPFA0A9 -- Object not found -- is returned when there is no object. CPFA0DA -- Object name is a directory -- is returned when the name is found but it's a directory. CPCA08A -- Object checked in -- is sent as an *INFO message when a valid streamfile name is supplied and it exists. There is also the CHKOUT command. If these commands are used, it might be best to use CHKOUT first; and then use CHKIN after success with CHKOUT. CHKIN is as simple as it gets when requirements are simple. The CHKOUT/CHKIN pair can give increased control. — Thomas Liotta
- Does the RNM cmd change the object attributes (i.e. the changed, accessed or created dates)? If yes, this may not be the best way to check for an IFS object's existence.— Don Sternberg
MORE INFORMATION ON THIS TOPIC
The Best Web Links: tips, tutorials and more.
Ask your programming questions--or help out your peers by answering them--in our live discussion forums.
Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.