Each procedure has its own table buffer for each table in the application. This allows a procedure to access any table in the application. The procedure’s table buffers exist only as long as the procedure is running.
To use a form’s table buffer (the form where the calling script is located), the table buffer must be passed as an inout parameter to the procedure. After the form’s table buffer has been passed to the procedure, the procedure will actually be using the form’s table buffer, not just a copy of the contents of the table buffer.
This example shows how a table buffer is passed to and used in a procedure. The table buffer passed is the table buffer used by the form where the calling script is located. The table buffer must be passed as an inout parameter.
Procedure Name |
Balance_Warning |
inout table Customer_Data; warning 'Customer Name' of file Customer_Data + " has an unpaid balance.";
The following script calls the Balance_Warning procedure, passing the table buffer for the Customer_Data table to the procedure. The Customer Name field in the table buffer is used in the warning message.
call Balance_Warning, table Customer_Data;
In a procedure script, you have the flexibility to open a table based upon its name, rather than by passing the table buffer into the script or explicitly stating the table name in the script. You do this by declaring a local anonymous table for the procedure and using the open table statement and the with name clause to open a table. Anonymous means that the name of the table being opened isn’t known when the procedure is written. The ability to open a table by name is useful for routines such as table maintenance, when you want to specify which table to perform maintenance on at runtime.
This example counts records in a named table. A table name is passed into the procedure as a string. A local anonymous table is declared. The table is opened using the open table statement and the with name clause. The procedure returns the number of records in the table as an out parameter.
Procedure Name |
Count_Table_Records |
in string table_name; out long record_count; local anonymous table working_table; {Open the table named in the table_name in parameter.} open table working_table with name table_name; record_count = countrecords(table working_table);
Local anonymous tables don’t allow you to have several instances of the same table open in a procedure. They allow you only to open a table based upon a name that is specified at runtime. |