Open

See Also: Close, Declare_Datafile, Relate, Opening a Table Without Using an Intermediate File

Purpose

To open a table using the specified table name or table number.

Syntax

Open [{rootName} As] {table-name} [Mode {table-mode}] [{index}]

table-mode: the mode to open the table in: either DF_SHARE or DF_EXCLUSIVE; if omitted, DF_SHARE is used (the table is opened non-exclusively)

 

Driver-specific open syntax:

When using a database other than the embedded database, a driver may support a special form of the Open As command, where rootName contains information to locate tables.

See Driver Special Open for syntax and further information.

What It Does

Open opens table, including all associated index files and makes its fields and records available for processing by the program.

Open opens the table set identified in the filelist for table unless you use the as option. Open as allows you to specify the full path (with no extension) of the table set to open, regardless of what is contained in the filelist. This path may contain a driver name (e.g., odbc_drv:person would open the table person in an ODBC data source). If the as option is used, and table contains 0, the table's number (from the FILELIST.CFG) will be retrieved, and placed into table.

If you are using a database other than the embedded database, consult the documentation for the driver you are using for more information about opening tables in the database you are using. Specifically, see Driver Special Open for using "Open As" with client/server tables.

Example

Integer hTable

Move 0 to hTable

Open "employee" as hTable

In this example, if employee is Number 7 in the filelist, then hTable will contain 7. If employee is not in your current filelist, you will get an error (see the note later in this article to open a table that is not in your filelist).

This method can be employed when you would like to use a string variable to open a table, and you need to know its table number. Commands which take a table number as a parameter (e.g., Get_Attribute) can then be called for this table.

Index at the end of the command causes the index of that number to be buffered in memory. This is of use if your program produces a report of record data from table in the order of an index.

Open customer

This command opens the customer table.

Open vendor 3

This example opens database table vendor and buffers part of its third index in memory, thereby making sequential access to its records faster.

Open "account\delinqs" as  vendor

This example opens table set delinqs.* in folder \account. The table is referred to throughout the program as vendor, even though that is not its folder Rootname in the filelist.

The as option is useful when you would like to choose a physical table set to process at runtime. In this case, the value of rootName may be input at runtime through a variable before as.

To do this, table should be in your filelist, and its fields must have the same names, and be of the same types (String, Number, Date, or Text) and in the same order, as they are in rootName.

Another use for the as option is for opening a table with a generic table definition. For example, you have three vendor tables: vendor1, vendor2 and vendor3. If they all have the same physical structure (field names, types and lengths), then you could have one .FD file for all three: vendor.fd.

open "vendor1" as vendor

This example looks for the file vendor.fd, and if it is found, opens vendor1 using the table definition in vendor.fd.

open Customer Mode DF_EXCLUSIVE

This example opens the customer data table in exclusive mode.

Notes

 

open "test" as 11

This example opens test, regardless of whether it is in your filelist, and regardless of whether or not test.fd exists.

 

Open (Trim(monument.tablename)) as rushmore