%TruncateTable meta-SQL element
Syntax
%TruncateTable(table_name)
Description
%TruncateTable deletes all the rows in a table.
Note:
You must use a table name, not a record name, with this statement.
On all databases, the
use of %TruncateTable causes an implicit commit. The rows deleted
by this command, and any other pending database updates, are all committed.
To postpone the commit until subsequent database updates have been
successfully completed, use the SQL statement DELETE FROM table_name
or the statement IMPORT REPLACE WITH NULL instead of %TruncateTable(table_name). The
advantage of using %TruncateTable is that its execution is faster
than either of the SQL statements. %TruncateTable is often used for
removing rows from a work table or a temporary table.
If you're calling %TruncateTable from an Application Engine program step, you should commit after the step that immediately precedes the step containing the %TruncateTable statement. Also, do not use %TruncateTable on a step that is executed multiple times within a loop. In general, it's best to use this construct early in your Application Engine program as an initialization task. In addition, avoid using this meta-SQL when your Application Engine program is started from the CallAppEngine function.
If a commit is not possible, Application Engine replaces the meta-SQL with a Delete From string. This ensures restart integrity when your program runs against a database where there is an implicit commit associated with Truncate Table or where rollback data is not logged.
For databases that either execute an implicit commit for %TruncateTable or require a commit before or after this meta-SQL, replace %TruncateTable with an unconditional delete in certain circumstances.
Example
If you use %TruncateTable with %Table, you must specify the full name of the table. For example:
%TruncateTable(%Table(BAS_ELIG_DBGFLD))
The following is a code example:
%TruncateTable(PS_TEMP_TABLE)
Related Topics