Share via


Temporary Tables

A temporary table is a temporary variable that holds a table. A temporary table is used as a buffer for table data in your C/AL programs. For more information about C/AL, see Introduction to C/AL.

You can use a temporary table just like you use a database table. The differences between a temporary table and a database table are as follows:

  • A temporary table is not stored in the database, but is only held in memory until the table is closed.

  • The write transaction principle that applies to a database table does not apply to a temporary table. For more information, see Write Transactions and Recovery.

Dd355211.f8b33fa0-1e55-4df8-b330-f4bd823faee3(en-us,NAV.71).png

Advantage of a Temporary Table

The advantage of using a temporary table is that all the interaction with a temporary table occurs on the client. This reduces the load on both the network and the server.

When you want to perform many operations on the data in a specific table in the database, you can load the data into a temporary table when you modify it. Loading the data into a temporary table speeds up the process because all the operations are performed locally on the client.

Defining and Using a Temporary Table

You must define the temporary table before you can use it in your C/AL code. The variable that holds a temporary table is defined just like any other global or local variable.

To define a temporary table

  1. On the Tools menu, choose Object Designer, and then create a new table.

    For information about how to create a table, see How to: Create a Table.

  2. Choose View, and then choose C/AL Globals or C/AL Locals, depending on whether your variable will be global or local.

    If you choose C/AL Globals, the C/AL Globals window appears.

    C/AL Globals window

  3. Enter a name for the temporary table variable, and enter or select Record as the data type. Use the up arrow in the Subtype field to select the table to copy.

  4. With the cursor still on the line that defines the temporary table, choose View, and then choose Properties (Shift+F4) to display the Properties window.

    Properties window

  5. Change the value of the Temporary property to Yes.

After you have created a temporary table, you can use it in your C/AL code. You can apply filters and perform searches just as you can with a database table.

See Also

Other Resources

Special Tables