Modifier

Partager via


Query.Close() Method

Version: Available or changed with runtime version 1.0.

Closes a query data set and returns the query instance to the initialized state. The following code shows the syntax of the CLOSE method. Query is a variable of the Query data type that specifies the query object.

Syntax

 Query.Close()

Parameters

Query
 Type: Query
An instance of the Query data type.

Remarks

The Close method does not clear any filters that are set by the SetFilterS method. If you want to clear the filters, then you must call the Clear method.

In most cases, you do not have to call the Close method explicitly. The Close method is called implicitly when the following conditions are true:

Example

The following example demonstrates how to use the Close method on a query. The example code sets filters on the query, opens the query, and then reads the dataset. For each row in the dataset, a message box is displayed that contains the values of the columns in the row.

This example requires that you create a query called Customer_SalesQuantity that is links table 18 Customer with table 37 Sales Lines from the CRONUS International Ltd. demonstration database. Include columns for the Name and No. fields from the Customer table and the Quantity field from Sales Lines table.

The following AL code opens the query, reads each row of the dataset, and then closes the query. You can add the code to a codeunit, and then run the codeunit to see the results.

var
  MyQuery: Query "Customer SalesQuantity";
  Text000: Label 'Customer name = %1, Quantity = %2';
begin
    // Sets a filter to display only sales quantities greater than 20.  
    MyQuery.SetFilter(Quantity, '>20');   
    // Runs the query.  
    MyQuery.Open;  
    // Reads each row in the dataset and displays a message with column values.   
    // Stops reading when there are no more rows remaining in the dataset (Read is False).  
    while MyQuery.Read do  
    begin  
      Message(Text000, MyQuery.Name, MyQuery.Quantity);   
    end;  
    MyQuery.Close;  
end;

Query Data Type
Get Started with AL
Developing Extensions