IF EXIST


The IF EXIST statement determines the existence of a specified file.

    ••••• IF EXIST ••• ••••••••            FAIL • CACHE? •
    (1)            (2) (3)                     (4)      (5)

(1) T/F execution conditions

(2) Application ID

(3) File name

(4) Fail action (0=nothing, 1=warning, 2=error, 3=cancel)

(5) Cache? (Y=cache version, N=disk version)

Sets True/False Status Indicator

The next true/false status indicator is set to T if the file exists, and to F if it does not. If the file does not currently exist, the FAIL parameter determines what additional action to take. In addition, on a false condition, the predefined field STATUS CODE returns a token indicating the reason for an I/O command failure. This token can be used as a key to read the system message file to obtain a descriptive I/O error message (see STATUS CODE for details).

Using the Statement

The application ID and file name to locate are specified in the statement. Additional information that can affect the location of the file may be contained in the predefined fields DATABASE or NEXT DATABASE.

The file name references a file that is defined in the data dictionary of the specified application ID. You can set the NEXT DATABASE predefined field to the database ID of the database in which the file should be located.

If NEXT DATABASE is blank, the DATABASE predefined field is used. The NEXT DATABASE field is set to blank by the IF EXIST statement, regardless of whether or not the file was successfully located.

Execution Errors

Serious problems encountered while trying to open the file, such as a file structure/data dictionary mismatch, cause a non-recoverable runtime error to occur, regardless of the FAIL parameter.

Related PDFs

DATABASE, NEXT DATABASE

Related Statements

CLOSE, CREATE, OPEN, SCRATCH

Example

In the example below, the General Ledger Parameters file is accessed to determine if it exists. If it does not exist, an error is displayed or printed; if it does exist, the record is read; and if the record does not exist, an error is displayed or printed.

          IF       TAR PARAM KEEP HIST CALEND     EQ     0
    T     IF EXIST TGL PARAM               FAIL 0 CACHE? N
    TF    ERROR    General Ledger Parameters File Does Not Exist
    TT    READ     TGL PARAM                  HOLD 0 FT 0 BY
    TTF   ERROR    General Ledger Parameters Record Not on File