Check File Existence

STATE appname/filename.filetype -TYPE RETCODE &RETCODE

where:

appname

Is the application under which the file is stored.

filename

Is the name of the file.

filetype

Is the file type or extension of the file.

If the file exists, the &RETCODE value will be 0 (zero). Otherwise, it will be non-zero and can be used to further direct the logic of the application, typically in a -SET or a -IF command. The STATE command will also output a not found message. To suppress this message, use the SET TRMOUT={OFF|ON} command.

For example, the following STATE command checks the existence of the file myproc.fex in the baseapp application. The STATE command displays a message if the file does not exist. The -TYPE command displays the value zero (0) if the file exists or the value -1 if the file does not exist.

STATE baseapp/myproc.fex
-TYPE RETCODE &RETCODE

Checking the Existence of a File With the STATE Command

The following partial example suppresses the message returned by the STATE command, issues the STATE command to check if the file myproc.fex exists in the baseapp application, checks the return code, and creates the file if it does not exist, before continuing with the next step in the application. If the file does exist, the code immediately transfers to the next step in the application, (-RESUME label):

SET TRMOUT=OFF
STATE baseapp/myproc.fex
SET TRMOUT=ON
-IF &RETCODE EQ 0 THEN GOTO RESUME;
...
* Some code to create the file goes here
...
-RESUME