Switch to: V12V11V10V9V8V7V6V5

Report Editor - Sub Report : Map Parameters Dialog Help

Using the Map Parameters Dialog, you can set correspondence between records, returned by the query of the main report, and records, returned by the query of the subreport limited by the condition with parameter.

 Report Editor - Sub Report : Map Parameters Dialog

Parameters

  • Parameter โ€“ The name of parameter in the query of the subreport.
  • Expression โ€“ The expression, that should be substituted instead the parameter.
  • Description โ€“ The description of the parameter.

When map parameters is declared, reports engine will substitute records in the subreport, that satisfy the condition specified in the map parameters, for the current record in the main report. That is, in the subreport will be shown records for which performed condition defined in the query of subreport, in which instead of parameter will be substitute a value of corresponding field from the current record of the main report.

Test

The Test tab shows a result of execution query:

Report Editor - Sub Report : Map Parameters Test

Example

Suppose you have a database with tables Customers and Orders:

As example, we will create a report, that will contain a list of customers, and list of orders for each customer.

Preparatory Steps

  • Create a query for report with list of orders.
       SELECT * FROM Orders WHERE Customer_Ptr = $P(Customer_ID)
  • Create a query for report with list of customers.
       SELECT * FROM Customers
  • Create a report, that will print the list of orders (it will be a subreport).

Subreport Example - Subreport

  • Create a report, that will print the list of customers (it will be a main report).

Subreport Example - Main Report

The Binding of Reports

Now you need to bind data in subreport with data in main report using, the map of parameters. For this - select property map_parameters in the properties inspector (make mouse click on edit button for the property, to open the dialog with map of parameters). To bind data in the subreport and main report - set the expression for parameters of subreport query. As shown on the image below:

Subreport Example - Map Parameters

That's all! Data is binded. To check go to the preview mode of the report:

Subreport Example - Preview

The subreport prints records that corresponds to the map of parameters.

How It Works

The reports engine generates a content of a report consistently, record by record. A data for the main report is taken from the source query. A data for the subreport is taken from the specifc query, that generated by reports engine from the source query of the subreport, and from the map of parameters, that defines a relations between data in the reports. The reports engine adds to the query of the subreport the condition of the selection, that defined by the map parameters.

Then, the query for the subreport will have the next structure:

SELECT * FROM Orders WHERE Customer_Ptr = ?

In the query instead of ?, the database engine substitutes the current value of a field of the query of main report, that mapped to the parameter of the subreport query. In this example it will be the value of ID field.