CREATE


The CREATE statement makes certain that a file exists and is opened for use. If the file does not already exist, this statement creates the file. CREATE is often used following a SCRATCH statement; the combination has the effect of clearing all records in a file.

     CREATE     SHARE?   FAIL CACHE
    (1)            (2) (3)             (4)     (5)      (6)

(1) T/F execution conditions

(2) Application ID

(3) File name

(4) Share the file? (Y/N)

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

(6) Cache type (NONE, LOAD, AUTO, NOLOAD)

Sets True/False Status Indicator

The next level of the internal true/false status indicator is set to T if the file is successfully created. The indicator is set to F if creation fails for any reason other than the file already exists. In this case, 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

You specify the application ID and file name for the file to be created in the statement. The SHARE? parameter determines whether or not other users are permitted to update the file while it is open. Additional information that can affect the location of the file may be contained in the predefined fields DATABASE or NEXT DATABASE.

You can use the NEXT DATABASE predefined field to specify in which database you want the file created. If NEXT DATABASE is blank, the current database (located in DATABASE) is used to create the file. Note that NEXT DATABASE is modifiable, whereas DATABASE is not, and that NEXT DATABASE is set to blank by the CREATE statement.

The CREATE statement can also create and open a cached instance of a file. Specifying a CACHE option other than NONE causes a cached instance of a file to be created in memory and opened instead of the normal disk instance of the file. This can result in significant reductions in File I/O during posting and reporting processes. Once you have created a cached instance of a file, all I/O that follows will reference the cached instance of the file, not the disk instance, until you OPEN the disk version. If you rewrite, delete, or write records to the cached version of the file, the disk version of the file will not be updated. If the disk version of the file changes after you create and load the cached version of the file, the cached version of the file will not reflect those changes.

If NEXT DATABASE is specified for the CREATE statement which creates a cached file, then the value of NEXT DATABASE determines the source database for automatically loading the cache. Otherwise, the current database determines the source of the file used to load the cache.

After creating a cache, you can switch between the cache and disk versions by using the OPEN statement.

Valid values for the CACHE option are:

    NONE creates and opens the file as a normal, non-cached file. This is the default value.

    NOLOAD creates and opens the cached version of the file without loading any records into it. Records are added to cache via the WRITE statement.

    LOAD creates and opens the cached version of the file and loads it from the disk version of the file.

    AUTO creates and opens the cached version of the file and dynamically populates the cache from the disk version of the file as records are individually read.

Related PDFs

DATABASE, NEXT DATABASE

Related Statements

CLOSE, IF EXIST, OPEN, SCRATCH

Example

The following example scratches and then recreates and opens a file called MONTHTRX, allows it to be updated by other users, and generates an error message if the operation fails for any reason.

          SCRATCH  TGL MONTHTRX            FAIL 0 CACHE? N
          CREATE   TGL MONTHTRX  SHARE? Y  FAIL 0 CACHE NONE
    F     ERROR    Unable to Create TGL MONTHTRX File!