Export (0) Print
Expand All

CLOSE Function (Query)

Closes a query dataset and returns the query instance to the initialized state.

The following code shows the syntax of the CLOSE function. Query is a variable of the Query data type that specifies the query object.


The CLOSE function does not clear any filters that are set by the SETFILTERS function. If you want to clear the filters, then you must call the CLEAR function.

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

The following example demonstrates how to use the CLOSE function 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 do the following:

  • 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.

    For step-by-step instructions for creating this query, see Walkthrough: Creating a Query to Link Two Tables.

  • Create the following variable and text constant

    Variable name DataType Subtype




    Text constant name ENU Value


    Customer name = %1, Quantity = %2

The following C/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.

// Sets a filter to display only sales quantities greater than 20.
MyQuery.SETFILTER(Quantity, '>20'); 
// Runs the query.
// 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).
  MESSAGE(Text000, MyQuery.Name, MyQuery.Quantity); 

© 2015 Microsoft