Equinox Online Help - Language Reference - A to Z

Home

Subtable ... End Subtable

Applies to
SyntaxSubtable TableName [, Unlinked]
[statements]
[Exit Subtable]
[Continue Subtable]
End Subtable

Note that you can use EndSubtable instead of End Subtable.

Action[Statement] This statement defines a statement block, within which the developer may temporarily access a new home table. If the specified table is locked by another user, then the system workarea SysError is set to a non-zero value.
ScopeUsable anywhere.
Notes

You use this statement to create a subtable block. A subtable block is a powerful structure, within which you can access a new home table and directly control the Equinox database manager. Inside a subtable block, all database control passes to the developer, who is responsible for choosing an index and finding records.

The block name, TableName, sets the home table for the block. When the End Subtable statement is reached, Equinox reverts to the original home table again.

The Continue Subtable statement causes control to pass to the first line after the Subtable statement. The Exit Subtable statement causes control to pass to the line following End Subtable. Note that you may nest subtable blocks, if required.

When a subtable block is started, it will attempt to link the home table inside the block with the home table outside the block, in the same way that the SameRecord statement does. To suppress this, include the Unlinked clause in the declaration.

CategoryFlow Control
See Also Block_EndBlock, BreakPressed, Continue, Execute, EnableInput, Exit, For...Next, Goto, If_Then, Repeat_EndRepeat, Repeat_Until, Return, Sleep, Switch, While_EndWhile
Example

The following example calculates the total number of orders for the current customer. When used with child tables, the special index name DefaultIndex selects a child index (which can find records only for the current parent).

subtable orders
SetIndex DefaultIndex
NoOrders = 0

FirstRecord

while not syserror NoOrders += 1
NextRecord
end while
end subtable | orders

The next method sets up three separate indexes for customers with unpaid invoices more than 1, 2, or 3 months old. The method examines each customer's invoices in reverse date order. If it finds an unpaid invoice, then the customer's record is added to the appropriate index.

The subtable blocks are used to step through the customer and invoice records. Note that the system workarea SysError is set to True when no more invoice records can be found for the current customer.

The method uses two fields: InvoicePaid (a logical value) and InvoiceDate. One index is used, InvoiceDate, which is a child table index.

logical marked1,marked2,marked3
number DebtorDays

BlankIndex debtors1
BlankIndex debtors2
BlankIndex debtors3

subtable customer
SetIndex DefaultIndex
FirstRecord

while not syserror | Repeat For every customer
marked1 = False
marked2 = False
marked3 = False

subtable invoice
SetIndex IinvoiceDate
LastRecord

while not syserror | Repeat For every invoice
if not InvoicePaid then
DebtorDays = Today - InvoiceDate

| mark an index unless already done
switch DebtorDays
case < 30 | 0-1 Month (no action)
| Do nothing
case < 60 | 1-2 Months
if not marked1 then
MarkIndex debtors1
marked1 = True
end if
case < 90 | 2-3 Months
if not marked2 then
MarkIndex debtors2
marked2 = True
end if
default | more than 3 Months
if not marked3 then
MarkIndex debtors3
marked3 = True
end if
end switch end if

| If the last unpaid invoice was more than 3
| Months old, there's no point in continuing

if marked3 then exit subtable

PreviousRecord | Next invoice
end while | more invoices
end subtable | invoice
NextRecord | Next customer
end while | more customers
end subtable | customer

You could use the following example code structure to abandon an attempted operation on a locked table.

subtable customer
if syserror then exit subtable | table is locked
...
end subtable | customer