DEFAULT TABLE
DEFAULT TABLE ( aTable )
Parameter | Type | Description | |
---|---|---|---|
aTable | Table | → | Table to set as the default |
Description
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. In particular, note that DEFAULT TABLE takes priority when you use, for example, the DIALOG command with a project form and there is a default table form with the same name.
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:
FORM SET INPUT([Table];"form")
If the default table is first set to [Table], the same command could be written this way:
FORM SET INPUT("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.
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.
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 FORM SET INPUT and ADD RECORD commands both require a table as the first parameter:
FORM SET INPUT([Customers];"Add Recs")
Repeat
ADD RECORD([Customers])
Until(OK=0)
Specifying the default table results in this code:
DEFAULT TABLE([Customers])
FORM SET INPUT("Add Recs")
Repeat
ADD RECORD
Until(OK=0)