Navigation:  Reference > Commands >

Open File

Print this Topic Previous pageReturn to chapter overviewNext page

 

This command will set up a file so that you may access data from it or write records to it from within your program.

 

OPENV f/c/e Required - The name of the file to be opened. You may specify the entire file name including disk drive specifier, path, filename and extension.  If this is a TAS Professional file then the extension defaults to .B (other extensions are provided by the extension option (EXT) or are specified by a previously set default - see CO or the SETUP program).  The filename can be a field, expression or alpha constant.  If a path is specified in FILELOC.B and not here, that value will be used.  If a path is included here it will be used no matter what's in FILELOC.B for this file.

 

FNUM fn/v Required - After the program opens a file (of any type) it returns a value that represents the number of the file opened.  It is used by all the other commands that access the file for any purpose.  This must be an I type field.

 

TYPE sac TDFXBC - The type of file being opened.  The options are: T - TAS Professional, D - dBASEIII+ (non-CodeBase), F - Fixed length records (SDF), X - Text type, B - non-TAS Professional Btrieve files and C - Codebase.  TEXT is for files such as letters, or others that have records that are not all the same size.  Each TEXT record is terminated by a CR/LF (carriage return/line feed - 0Dh/0Ah) pair.  In FIXED files all records are of the same length; they are also terminated with CR/LF pairs.  D is for files created by dBASE III+ or those that fit the same requirements.  You must still set the size for the D files, although the program knows where the data actually starts and can keep track of the number of records.

NOTE:  D type files are different than CodeBase in that we don't use indexes, don't open memo files, and the layout isn't a part of FILEDICT.B.  In most cases you will find it much more expedient to open these as CodeBase files since you will have more flexibility and capability than under just plain dBASEIII+.  However, if you don't have index files and you don't have any memo files you will find it just as easy to open the file as a type T as a type D.

 

       NOTE:  What you have specified in your SETUP program determines whether you open Pervasive (Btrieve) files for type T or CodeBase (DBF) files.  TAS Professional programs will work the same regardless of the file type!  However, in the case of Pervasive (Btrieve) type files the extension will be B+company code.  CodeBase will always be DBF (main data file), DBT (memo file) and MDX (index file).

 

EXT f/c/e If you wish to open a copy of the file with an extension other than the current default value (.B or whatever the company_code value is set to), you may specify up to 3 characters here.

 

       NOTE:  In all non-TAS files (T, D, F, X and B) you must specify the extension if you haven't done so in the file name.  In T and C type files the first character of the extension must be B.

 

LOCK sac   NRFXOD - The type of locking to use. N - none, R - record, F - file, X - read-only, O - Opportunistic  locking and D - Deny access to others (exclusive access).  The default is N - none if multi-user is not checked in the SETUP program and R if it is.  R type locking will only lock a record at a time.  You can only have one record locked in a file at one time.  Multiple record locks are not available.  When you use F type locking (File), no one else will be able to open the file for any purpose other than read-only (X type locks).  Also, if any one has the file open before you try to set F type locking you will get an error when you try to open the file (see OPEN()).  Use D (deny access) when you are going to re index the file or create a temporary index.  If you have the lock set to D other users won't be able to open the file at all.

 

       NOTE:  This option is ignored for non-TAS files.

       

       NOTE:  In Btrieve files F and D type locks are the same.  In CodeBase files the F type lock will only keep another user out if they try to lock the record, where D will keep another user out regardless.

 

       NOTE:  Opportunistic  locking:  This means the record is not locked unless you execute the REC_LOCK() function or, if you have a TTASNavigator attached to the file, if your user clicks on the Edit button or your code "clicks" on the button (see the ClickBtn property in TTASNavigator).  The benefit of this is that you can allow your user to view records that may be edited (and locked) without locking them when read.  Also, if you save a new record, all the appropriate locks will be set internally.

 

OWNER f/c/e A maximum 8 character code to be specified if the file is protected with the OWNER command.  This applies to Pervasive (Btrieve) files only.

 

PATH f/c/e You may specify the path for this file if you wish to override the value in the FILELOC.B file.

 

       NOTE:  The path value must end with a backslash character (\).

 

FD f/c/e You may specify the file descriptor name for this file if it is not in FILELOC.B but the actual file layout is defined in the Data Dictionary.  This allows you to compile a program using one data dictionary and then run it on a system that has a different data dictionary without having to worry whether or not that FD exists in the new dictionary.

 

SIZE f/c/e   In the case of a non-TAS Professional file you must specify the maximum size of the record.  In the case of a text or fixed length type file this must also include the final CR/LF pair (2 extra characters).        

 

       NOTE:  If the non-TAS file is defined in the data dictionary you do not need to include this value.

 

BUFF fn/v In the case of a non-TAS Professional file you must specify the buffer that will hold the record when it is read, unless it is defined in the file Data Dictionary.  You may use multiple fields to make up a buffer; however, you would specify just the first field in this case.  You may also define a buffer in a program for a TAS Professional file.  To use the buffer in the program instead of the normal buffer created in memory specify the name of the first field here just as you would with a non-TAS file.

 

       If you are specifying a buffer for a non-TAS file don't forget to include the extra CR/LF bytes at the end of the record in both the size of the buffer and the size of the record if stipulated in this command.

 

       NOTE:  Non-TAS files that are defined in the data dictionary allocate their own buffers automatically just like regular TAS files.

 

CREATE If this option is included in the command the program will automatically create a new file upon opening.  If the file exists it will be deleted.  This only applies to file types:  F and X.

 

       NOTE:  If the file doesn't exist it will be created automatically regardless of whether or not this option is included.  If the file doesn't exist prior to the OPENV command the new file will have a size of 0 bytes.  This can be checked using the FLSZE() (file size) function after the file is opened or the FILE_EXISTS() function before. If CREATE is not included in the command the data will be appended to the already existing data to the file/table.

 

NOCLRNormally the buffer is cleared when a non-TAS Professional file is opened.  If you have data in it already, and do not want to clear it then include this option in the command.

 

ADDALLFLDSIf you specify this option the program will load all the fields from the data dictionary when the file is opened.  This is only necessary if you have not specified any of the fields from this file within the program itself when it was compiled.

 

       NOTE:  During compilation the fields that make up any files used in the program will be automatically added to the field list.  This will allow you to add fields to the screen form or report form after the program has been compiled and without recompiling.

 

 DUPECHECKThis will open a second version of the same file so it can be used in the ifdupcb() function. This only applies to codebase type files.

       

       NOTE : if you are trying to use the ifdupcb() function and do not have this set in the openv the ifdupcb() will not work.

 

 

COMMENTS

If the file is defined in the File Data Dictionary any fields that are a part of it cannot be accessed in the program until the file is opened.  Any attempt to do so will generate a warning error at runtime.

 

With this command you may open dBaseIII+, Text, and Fixed Length records and treat them as though they were standard TAS Professional files.  This means you can do standard searches on the files, read and write records at will and in general treat them just as though they were Btrieve files.  ALL commands that access files can be used to access these non-TAS files also (except the DEL and DALL commands).  You would also use this command to open non-TAS Btrieve files where the file layout is a group of defined fields in memory (predefined or added during operation) instead of a standard defined record in the data dictionary.  This command brings a level of flexibility to file handling not found in other 4GLs.

 

You can also define non-TAS Professional files in the file Data Dictionary.  Make sure you set the proper file type when initializing the file.  When a file is in the file Data Dictionary all the rules that apply to a standard TAS Professional file also apply to it, including setting up the file name, etc.  This gives you the ability to access non-TAS files as easily as regular TAS files.

 

NOTE:  The maximum number of files that may be open at one time is 256.  This limit applies across all programs that are currently active.

 

NOTE:  In TAS Professional 5.1 and previous, there was an ERR option.  That option is ignored in TAS Professional (Windows GUI) programs. to check this use the flerr() function

 

NOTE: If you are using TAS 5.1 type programs using the where you mount screens and reports with the MOUNT Command. WARNING: Do not execute an OPENV after doing a MOUNT command it will not execute. To find out more about the tas 5.1 command please look this command up in the tas 5.1 manual.

BYTES,
PCHR
ASC

If you want to have a BYTE stay a byte avoid converting a BYTE (which is a numeric field) to an A type field as the A type field will convert any nondisplayed CHAR between 0-31 into a 32.

When reading a binary table use READ instead of FINDV next.

Also see DEFINE,  PCHR,  ASC, READ

 

SEE ALSO                        

CLOSE, FINDV, SAVE, DEL, ROPEN READ WRITE

 

 


Page url: http://www.cassoftware.com/tas/manual/openfilevariable.htm