COUNT Function (Record)

Counts the number of records in a table.

Number := Record.COUNT

Parameters

  • Record
    Type: Record Refers to the table to be counted.

Property Value/Return Value

Type: Integer

The number of records in the table.

Remarks

This function returns the number of records that meet the conditions of any filters associated with the records. If no filters are set, then the function shows the total number of records in the table.

Note

The COUNT function does not lock the table before retrieving the number of records in the table. This means that the function reads both uncommitted and committed data, which could cause the number of records that are returned to be inaccurate. To ensure that the count is accurate, use the LOCKTABLE Function (Record) before you use the COUNT function.

In previous versions of Microsoft Dynamics NAV, the COUNT function ignored security filters and always returned the total number of records unless you called the SETPERMISSIONFILTER function to get a filtered count. In Microsoft Dynamics NAV 2015, the COUNT function adheres to the SecurityFiltering Property. For more information, see Security Filter Modes.

Example

This example requires that you create the following variables.

Variable name DataType Subtype

CustomerCount

Integer

Not applicable

CustomerRec

Record

Customer

CustomerCount := CustomerRec.COUNT;
// This statement assigns the number of records in the Customer table
// to the CustomerCount variable. This statement is the same as:
CustomerCount := 0;
IF CustomerRec.FIND('-') THEN
  REPEAT
    CustomerCount := CustomerCount + 1;
  UNTIL CustomerRec.NEXT = 0;

Retrieving the count by using the first statement in the example is much faster because only one command to the Database Management System (DBMS) is needed.

See Also

Reference

Record Data Type