PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
  • Overview
  • Report on independent query
  • Overview
  • Creating a report on independent query
  • Report on embedded query
  • Overview
  • Creating a report on embedded query
  • Using an item of the embedded query from a code of the report
  • Report based on a query with parameters
  • Printing a report based on a query
  • Printing a report based on a query without parameters
  • Printing a report based on a query with parameters
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Report based on a query
Overview
Queries are used to easily select records in one or more data files. Queries can also be used to perform calculations on the selected data. You can, for example, select all the orders for the customers living in New York City and calculate the total amount of orders per customer.
Using queries in a report allows you to easily create complex reports. The query pre-selects the records and the report organizes the selected data and performs the different calculations.
Caution: To optimize the report, we advise you to perform the calculations (totals on items for example) in the report (and not in the query).
Several modes can be used to create a report based on a query:
  • the query is created and saved in the query editor. The report is based on the file corresponding to the query ( .WDR file). The query can be re-used in another report, window, control, ... The query can be modified at any time in the query editor. The query is said to be independent. For more details, see Report on independent query.
  • the query is created when creating the report. The query is included in the report. No file specific to the query is created. The query can only be modified from the report where it was created. It cannot be re-used in another report, window, control, ... The query is said to be embedded. For more details, see Report on embedded query.
  • the query is based on data coming from a connection (not available in WINDEV Mobile). For more details, see Creating an SQL query via a connection (ODBC, Native Connectors, etc.).
    Remark: This type of report based on a query is available even if no analysis is associated with the WINDEV or WEBDEV project.
Tip: You have the ability to create, from the query editor, a report based on the current select query. To do so, on the "Create a report" tab, in the "Query" group, click "Data binding".
Remark: An independent query or an embedded query can accept parameters. For more details, see Report based on a query with parameters.
The report can be easily printed from your WLanguage programs. For more details, see Printing a report based on a query. This help page presents:
Report on independent query

Overview

The query must be created before the report (for more details, see Creating a query). When creating the report, all you have to do is specify the name of the query used.
If the query is modified in the query editor (deletion of result items for example), a synchronization screen is displayed when closing the query. This allows you to apply the modifications performed on the query to all elements that use this query (including reports).

Creating a report on independent query

To create a report on independent query:
  1. Click New in the quick access buttons.
    • The creation window appears: click "Report" then "Report".
    • The report creation wizard starts.
  2. Choose the layout of your report (table, form, label, ...). For more details, see The different types of reports.
  3. Select (if necessary) the report template to use. A report template is used to comply with a specific page layout. For more details on report templates, see Report templates.
  4. Select the data source of report ("From a data file or from an existing query").
  5. Select the query on which the report will be based. Only the queries found in the current application are proposed.
  6. To group the records, you have the ability to create breaks on the sort items. To create breaks, answer "Yes" to the question "Do you want to add some breaks into the report?".
    The wizard next step is used to select the sort items corresponding to the breaks. For more details on breaks, see Breaks in a report.
  7. For each item displayed in the report:
    • type the corresponding caption. This caption will be displayed:
      • before the item. For example:
        =Caption
      • in the column header (for the Table reports). For example:
        =Caption
        This caption can be modified in the report editor.
    • select the block where the control associated with the item will be printed. The positions of different controls can be modified in the report editor. For more details on the different blocks and their position in a report, see Report blocks.
  8. Modify (if necessary) the display order of controls in the report with the arrow buttons found on the right of table.
  9. If the query associated with the report contains at least one numeric item, you have the ability to perform calculations these items. Specify the calculation performed for each item (sum, average, ...). Two types of calculations are available:
    • general calculation: a Calculated control will be created in the End of document block.
    • calculation on break: a Calculated control will be created in the Break footer block. In the calculations on break, the result of the calculation is reinitialized after each break. To perform a calculation on break, a break must be found in the report currently created.
  10. Depending on the type of report currently created, indicate the specific options.
    Type of reportSpecific options
    Report based on a formForm image, printing the form image, ...
    Options presented in detail in Report based on a form
    Label reportFormat of labels, number of identical copies, ...
    Options presented in detail in Label report
  11. Specify the format of sheet on which the report will be printed. The report is printed in A4 format by default.
    Remark: By default, the report controls are displayed in a single column. To create a multi-column report, simply specify the desired number of columns in the "Format" tab of the report description window.
  12. Select the skin template of the report if necessary.
  13. Type the name and title of the report (name of ".WDE" file corresponding to the report). This name will be used to identify the report in your programs.
    WINDEV You can also specify whether the report can be modified by the end user in "Reports & Queries".
  14. Validate the report creation.
  15. The report editor automatically proposes to change the report format if the following conditions are fulfilled:
    • the report currently created includes a table.
    • the report format does not allow to display all table columns.
  16. Specify (if necessary) the mode for reducing the report size:
    • Print the report on several pages. In this case, the end user will have to group the pages. For more details, see Multi-page print.
    • Use the landscape mode.
    • Reduce the report size. Caution: according to the reduction percentage, the printed report may become unreadable.
  17. The report currently created is displayed in the report editor.
Report on embedded query

Overview

The query is created when creating the report. This query will be modified from the report editor ("Edit the query" in the context menu of the report). If modifications are performed in the query, the report editor lists these modifications as well as their incidence on the report.
Remark: To switch from the embedded mode to the independent mode (which means to extract a query from a report):
  1. Display the report based on the embedded query (in the report editor).
  2. Select "Edit the query" in the context menu of report. Another solution: on the "Modification" tab, in the "Report" group, click "Edit query". The query is displayed in the query editor.
  3. On the "Home" tab, in the "General" group, expand "Save" and select "Export .. To an independent query".
  4. Save the new query.

Creating a report on embedded query

To create a report on embedded query:
  1. Click New in the quick access buttons.
    • The creation window appears: click "Report" then "Report".
    • The report creation wizard starts.
  2. Choose the layout of your report (table, form, label, ...). For more details, see The different types of reports.
  3. Select (if necessary) the report template to use. A report template is used to comply with a specific page layout. For more details on report templates, see Report templates.
  4. Select the data source of report ("From a new query").
  5. The query creation wizard starts. Select the items used by the query.
    Remark: To simplify the selection of items, display them in alphabetical order or by associated file.
  6. Define the query characteristics (selection condition, group, sort, etc.) by clicking the corresponding button.
    For more details, see:
  7. Go to the next step.
  8. To group the records, you have the ability to create breaks on the sort items defined in the query. To create breaks, answer "Yes" to the question "Do you want to add some breaks into the report?".
    The next step is used to select the sort items corresponding to the breaks. For more details on breaks, see Breaks in a report.
  9. For each query item displayed in the report:
    • type the corresponding caption. This caption will be displayed:
      • before the item. For example:
        Label
      • in the column header (for the Table reports). For example:
        =Caption
        This caption can be modified in the report editor.
    • select the block where the control associated with the item will be printed. The positions of different controls can be modified in the report editor. For more details on the different blocks and their position in a report, see Report blocks.
  10. Modify (if necessary) the display order of controls in the report with the arrow buttons found on the right of table.
  11. If the query associated with the report contains at least one numeric item, you have the ability to perform calculations these items. Specify the calculation performed for each item (sum, average, ...). Two types of calculations are available:
    • general calculation: a Calculated control will be created in the End of document block.
    • calculation on break: a Calculated control will be created in the Break footer block. In the calculations on break, the result of the calculation is reinitialized after each break. To perform a calculation on break, a break must be found in the report currently created.
  12. Depending on the type of report currently created, indicate the specific options.
    Type of reportSpecific options
    Report based on a formForm image, printing the form image, ...
    Options presented in detail in Report based on a form
    Label reportFormat of labels, number of identical copies, ...
    Options presented in detail in Label report
  13. Specify the format of sheet on which the report will be printed. The report is printed in A4 format by default.
    Remark: By default, the report controls are displayed in a single column. To create a multi-column report, simply specify the desired number of columns in the "Format" tab of the report description window.
  14. Select the skin template of the report if necessary.
  15. Type the name and title of the report (name of ".WDE" file corresponding to the report). This name will be used to identify the report in your programs.
    WINDEV You can also specify whether the report can be modified by the end user in "Reports & Queries".
  16. Validate the report creation.
  17. The report editor automatically proposes to change the report format if the following conditions are fulfilled:
    • the report currently created includes a table.
    • the report format does not allow to display all table columns.
  18. Specify (if necessary) the mode for reducing the report size:
    • Print the report on several pages. In this case, the end user will have to group the pages. For more details, see Multi-page print.
    • Use the landscape mode.
    • Reduce the report size. Caution: according to the reduction percentage, the printed report may become unreadable.
  19. The report currently created is displayed in the report editor.

Using an item of the embedded query from a code of the report

To access an item of the embedded query from the code of a report, report controls or report blocks, use the following syntax:
MySource.MyItem
Report based on a query with parameters
An independent query or an embedded query can accept parameters. In this case, one or more selection conditions depend on a parameter during the execution of the query. This parameter can correspond to the value of an edit control found a window.
For example, to print the invoice for customer X, all you have to do is create a report based on a query with parameters. In this query, the parameter will be the customer name for example. Therefore, the value of the parameter must be specified before the report is printed:
  • during the test of the report based on a query with parameters, a window allows you to type the query parameters.
  • at runtime, the query parameters must be specified with iInitReportQuery (before using iPrintReport).

Important

If the query is created with Reports & Queries, there is no need to use iInitReportQuery to specify the query parameters. Indeed, when running a report on a query with parameters from Reports & Queries, a window allows you to enter the parameters of the query.
Remark: For more details, see Query with parameters.
Printing a report based on a query
To print a report based on a query, you must differentiate between two cases:
  • Report based on a query without parameters.
  • Report on a query with parameters
Remarks:
  • If parameters must be passed to the report, these parameters must be specified in iPrintReport, after the name of the report to print. For more details, see Report with parameters.
  • When used in the code of the report, the SourceName property allows you to get and change the name of the query associated with the report.

Important

In Reports & Queries, you can print a report:
  • by starting a print job (Print).
  • by testing the report (Go).
Therefore, no programming is required to print the report.
When printing a report based on a query with parameters, a window allows you to enter the parameters of the query.

Printing a report based on a query without parameters

To print a query without parameters, you must:
  1. Configure the report print destination:
    • WINDEV In WINDEV, with iDestination (report viewer, print in an HTML file, etc.).
    • WEBDEV - Server code In WEBDEV, with iDestination (print in an HTML file, etc.).
    • AndroidiPhone/iPad In Android and iOS, with iDestination (print in a PDF file).
    For more details, see Print modes of a report.
  2. Specify the name of the report to print with iPrintReport.
    For example:
    • WINDEV In WINDEV: to print the "RPT_Query" report:
      // Open report viewer
      iDestination(iViewer)
      // Print the RPT_Query report
      iPrintReport(RPT_Query)
    • AndroidiPhone/iPad In Android and iOS: to print the "RPT_Query" report:
      // Configures the print destination
      iDestination(iPDF)
      // Print the RPT_Query report
      iPrintReport(RPT_Query)
    • WEBDEV - Server code In WEBDEV: to print the "RPT_Query" report in HTML format:
      // Generates a unique file name
      UniqueFileName is string = fWebDir() + "\" + "RPT_Query_" + DateSys() + TimeSys() + ".htm"
      // Configures the print destination
      iDestination(iHTML, UniqueFileName)
      // Prints the RPT_Query report
      iPrintReport(RPT_Query)
      // Extracts the name and extension of the generated file
      FileName is string = fExtractPath(UniqueFileName, fFile + fExtension)
      // Sends the file to the browser
      FileDisplay(FileName)

Printing a report based on a query with parameters

To print a query with parameters, you must:
  1. Configure the report print destination:
    • WINDEV In WINDEV, with iDestination (report viewer, print in an HTML file, etc.).
    • WEBDEV - Server code In WEBDEV, with iDestination (print in an HTML file, etc.).
    • AndroidiPhone/iPad In Android and iOS, with iDestination (print in a PDF file).
    For more details, see Print modes of a report.
  2. Pass the parameters to the query with iInitReportQuery.
  3. Specify the name of the report to print with iPrintReport.
For example: The "RPT_Query" report is based on a query with parameters. The parameters expected by the query are the name and type of the company. These parameters have been entered in the window for starting the report print.
  • WINDEV WINDEV code:
    // Open report viewer
    iDestination(iViewer)
    // Pass the parameters to the query associated with the report
    iInitReportQuery(RPT_Query, CompanyName, CompanyType)
    // Print the list of companies
    iPrintReport(RPT_Query)
  • AndroidiPhone/iPad In Android and iOS:
    // Configures the print destination
    iDestination(iPDF)
    // Pass the parameters to the query associated with the report
    iInitReportQuery(RPT_Query, CompanyName, CompanyType)
    // Print the list of companies
    iPrintReport(RPT_Query)
  • WEBDEV - Server code WEBDEV code:
    // Generates a unique file name
    UniqueFileName is string = fWebDir() + "\" + "RPT_Query_" + DateSys() + TimeSys() + ".htm"
    // Configures the print destination
    iDestination(iHTML, UniqueFileName)
    // Passes the parameters to the query associated with the report
    iInitReportQuery(RPT_Query, CompanyName, CompanyType)
    // Prints the RPT_Query report
    iPrintReport(RPT_Query)
    // Extracts the name and extension of the generated file
    FileName is string = fExtractPath(UniqueFileName, fFile + fExtension)
    // Sends the file to the browser
    FileDisplay(FileName)
Remark: If some of the parameters expected by the query are not specified (value corresponding to NULL for example), the selection conditions corresponding to these parameters will be ignored.
Related Examples:
WD Reports Training (WINDEV): WD Reports
[ + ] This example presents the different methods for creating a report:

- prints based on different data sources (queries, variables, ...)
- prints based on controls (Table, Spreadsheet, PVT, ...)
- printing composite reports
- specific prints (portrait/landscape, report with watermark, report with bar code, ...)
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment