Skip to main content


Creates a file for sequential access.


CREATE filevar [THEN statements][ELSE statements]


filevar A file variable name used to refer to the file in Caché MVBasic. This filevar is obtained from OPENSEQ.


The CREATE statement is used to create a file for sequential access. To create a file, you must first issue an OPENSEQ statement, giving the fully-qualified pathname for the file you wish to create. Because the file does not yet exist, the OPENSEQ appears to fail, taking its ELSE clause and setting the value returned by the STATUS function to -1. However, the OPENSEQ sets its filevar to an identifier for the specified file pathname. You then supply this filevar to CREATE to create a new file.

You can optionally specify a THEN clause, an ELSE clause, or both a THEN and an ELSE clause. If the file creation is successful, the THEN clause is executed. If file creation fails, the ELSE clause is executed. The statements argument can be the NULL keyword, a single statement, or a block of statements terminated by the END keyword. A block of statements has specific line break requirements: each statement must be on its own line and cannot follow a THEN, ELSE, or END keyword on that line.

The CREATE statement is:

  • Optional if the first operation you perform on the new file is to issue a WRITESEQ. If you issue an OPENSEQ and then issue a WRITESEQ, this first write operation automatically creates the file.

  • Mandatory if the first operation you perform on the new file is to issue a WRITEBLK. The CREATE creates the file, and then you may issue a WRITEBLK to write to the file.

You can use the STATUS function to determine the status of the file creation operation. A successful file creation returns a status of 0. A failed file creation returns a status of -1, for any of the following reasons:

  • The directory specified in OPENSEQ does not exist. CREATE can create a file, but not the directory to contain the file. You can create the directory after issuing an OPENSEQ and then use the filevar returned by OPENSEQ to create the file.

  • The file already exists.

  • The specified filevar is invalid.

After creating a file, you can use the STATUS statement to obtain file status information. The file is open for read and write operations. You can use CLOSESEQ to release an open file, making it available to other processes.


The following example creates a new sequential file on a Windows system:

OPENSEQ "C:/myfiles/test1" TO mytest
   IF STATUS()=0 
   THEN PRINT "File already exists"
   ELSE PRINT STATUS();   ! returns -1
     CREATE mytest
     IF STATUS()=0
       THEN PRINT "File created"
       ELSE PRINT "File create failed"

See Also

FeedbackOpens in a new tab