Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Version: Available or changed with runtime version 16.0.
Deletes all records in a table that fall within a specified range, in an efficient maner. Keep in mind that Truncate allows for less concurrency than DeleteAll, as the entire table will be locked until the transaction is committed.
Syntax
[Ok := ] Record.Truncate([ResetAutoIncrement: Boolean])
Parameters
Record
Type: Record
An instance of the Record data type.
[Optional] ResetAutoIncrement
Type: Boolean
Specifies if the AutoIncrement column should be reset to start from the initial value, or if it should stay at the current value.
Tables without an AutoIncrement field ignore this parameter. The default is true.
Return Value
[Optional] Ok
Type: Boolean
true if the table supports truncate; otherwise, false.
If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.
Remarks
Truncate currently isn't supported in the following cases:
- Temporary tables, system tables, and tables of type other than Normal.
- When running within a try function.
- Tables that have a security filter applied.
- When the current filters contain flow fields, or use a high number of marked records.
- When the OnAfter/OnBefore events are subscribed for the table.
- Tables with media fields.
In this case, it's recommended to use DeleteAll instead.
Example
The following example demonstrates how to truncate all records in a table and capture the optional return value to avoid a runtime error when truncate isn't supported.
procedure ExampleTruncate()
var
MyRec: Record "Truncate Sample";
Ok: Boolean;
begin
Ok := MyRec.Truncate(true);
if Ok then
Message('Truncate Sample table truncated and AutoIncrement reset.')
else
Message('Truncate not supported; consider DeleteAll.');
end;
The following example demonstrates how to truncate records matching a filter (in this case the table's "Location Code" field). This approach is only recommended when the majority of records match the filter because Truncate is most efficient in such scenarios.
procedure ExampleTruncateFiltered()
var
MyRec: Record "Truncate Sample";
Ok: Boolean;
begin
MyRec.SetRange("Location Code", 'Red');
Ok := MyRec.Truncate(false);
if Ok then
Message('Filtered records (Location Code=Red) truncated (AutoIncrement preserved).')
else
Message('Filtered truncate not supported; consider deleting manually.');
end;
See Also
Insert, Modify, ModifyAll, Delete, DeleteAll, and Truncate methods
RecordRef.Truncate([Boolean]) method
Record data type
Getting started with AL
Developing extensions