Caché MultiValue Basic Reference
[Home] [Back] [Next]
InterSystems: The power behind what matters   
Class Reference   

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:
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:
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