Best Practices - Opening and Closing Tables

The purpose of this document is to provide best practices to open and close tables.

Declaring a table in a Subprogram (called by Call), a Function (called by Gosub) or a Method (invoked by Fmet) does not cause any issue, even if the table was opened in the calling sequence. You can freely declare the tables you need in the routines you write. This is actually mandatory if you want to make sure the table was opened in the right context.

However, if you declare the same table in a sequence called by Gosub, it triggers an error. For example:

Local file BPCUSTOMER [BPC]Gosub DECLARE_TABLECall ANOTHER_SUBROUTINE...End$DECLARE_TABLELocal File BPCUSTOMER [BPC] : # Here, an error will occur (table already opened)...Return

If for any reason you want to re-open a table, you first have to close it by using the LogicClose instruction, whose syntax is as follows:

# Let's close the table BPCUSTOMERLogicClose File [BPC]

The table is no longer online, and none of the memory resources used are destroyed in the process. The execution of the following File instruction is also faster.

Caution: The clalev function should no longer be used for that purpose, as it as many side effects and is no longer safe.