version 3
DEFAULT TABLE (aTable)
Parameter | Type | Description | |
aTable | Table | Table to set as the default |
Description
DEFAULT TABLE sets aTable as the default table for the current process.
There is no default table for a process until the DEFAULT TABLE command is executed. After a default table has been set, any command that omits the table parameter will operate on the default table. For example, consider this command:
INPUT FORM ([Table]; "form")
If the default table is first set to [Table], the same command could be written this way:
INPUT FORM ("form")
One reason for setting the default table is to create code that is not table specific. Doing this allows the same code to operate on different tables. You can also use pointers to tables to write code that is not table specific. For more information about this technique, see the description of the Table name command.
DEFAULT TABLE does not allow the omission of table names when referring to fields. For example:
[My Table]My Field:="A string" ` Good
could not be written as:
DEFAULT TABLE ([My Table]) My Field:="A string" ` WRONG
because a default table had been set. However, you can omit the table name when referring to fields in the table method, form, and objects that belong to the table.
In 4D, all tables are "open" and ready for use. DEFAULT TABLE does not open a table, set a current table, or prepare the table for input or output. DEFAULT TABLE is simply a programming convenience to reduce the amount of typing and make the code easier to read.
Tip: Although using DEFAULT TABLE and omitting the table name may make the code easier to read, many programmers find that using this command actually causes more problems and confusion than it is worth.
Example
The following example first shows code without the DEFAULT TABLE command. It then shows the same code, with DEFAULT TABLE. The code is a loop commonly used to add new records to a database. The INPUT FORM and ADD RECORD commands both require a table as the first parameter:
INPUT FORM ([Customers];"Add Recs") Repeat ADD RECORD ([Customers]) Until (OK = 0)
Specifying the default table results in this code:
DEFAULT TABLE ([Customers]) INPUT FORM ("Add Recs") Repeat ADD RECORD Until (OK = 0)
See Also
Current default table, NO DEFAULT TABLE.