Skip to content

Using Basic Reports in Applications

The BasicReport class allows the developer to create code-based reports. While it is an extremely powerful report-processing tool, its output capabilities are limited. It is used when you wish to create non-proportional, single-font reports. You might think of it as a "line-printer-mode" reporting tool. It is also used as the basis for the cWinReport2 class. cWinReport2, which is a sub-class of BasicReport, adds a much more flexible output capability to BasicReport’s already considerable report processing capabilities.

Capabilities of BasicReport and cWinReport2

Both the BasicReport and the cWinReport2 sub-class have the following capabilities:

  • A report is broken down into sections. Sections correspond to the various parts of a report. The Header, Footer, Sub-header, sub-total, page totals, report totals, and body sections are all examples of report sections. Each section is defined by a special procedure named procedure_section.

  • You may choose to nest reports. This lets you perform "outer joins," in which a child file's records are ordered by a parent file's index. This allows you to print reports in a more sensible order. In addition, parent records with no relating child records may be printed or not printed (zero suppression).

  • Child-nested reports are automatically constrained by the parent report. A nested report (the report inside the main report) may itself contain child reports, or the report may have sibling reports (all constrained by the same parent).

  • Up to nine levels of breakpoints with subheaders and subtotals are supported. BasicReport supports nine levels at each level of report nesting. cWinReport2 supports a total of nine levels within a report (including nested child reports).

  • Page breaks with the proper display of all headers, sub-headers, and page totals are automatically supported.

  • Breakpoints may be based on just about anything, including field values, variables, window values, and functions (e.g., break (left(vendor.name, 1))).

  • Records may be found through data-dictionary objects or directly through the files. In addition, custom finding and relating of records is also fully supported.

  • They allow complete control over the finding of records. You can find up or down an index. Custom relating of records is supported.

  • They support the page-formatting options such as page_top, report_header, page_header, page_title, page_footer, report_footer, and page_bottom.

  • Printing of variable-length memo fields is fully supported.

  • They automatically support a status panel. A status panel is a panel that appears while the report is processing. This panel is used to show report progress and to provide a method for canceling a report.

  • Errors are directed to a single point in the report object, making it easy to control errors.

Reasons to Choose BasicReport

You would choose BasicReport for the following reasons:

  • Your report only requires a single, non-proportional font.
  • It is fast.
  • It is a good choice for creating large, high-volume reports.
  • It provides an excellent path for migrating character-mode-report-object (and report-macro) reports to DataFlex.
  • It can also be used as the report engine for other types of reports. Output could be sent to word processors, spreadsheets, etc.

Example of a BasicReport

Here is an example of a simple object based on the BasicReport class. Note that all of this code could be placed in the bottom code area of your Report View object.

/CustHdr Resident
Customer Name Listing                             Page:___.
Cst Id Name
----------------------------------------------------------------------------
/CustBody Resident
_____. ______________________________
/Footer Resident
Basic Report Sample: Printed on: __/__/__
/*
Object Cust_Report is a BasicReport
    Report_Main_File Customer
    Report_Index by Customer.Name
    Set Report_Title to "Printing Customer Names" // status panel title
Function Starting_Main_Report Returns Integer
    Integer RetVal
    Forward Get Starting_Main_Report to Retval
    SysDate Footer.1    // set date for report
End_Function
Procedure_Section Page_Top as CustHdr
    Print (Page_Count(self)) // show current page #
    OutPut_PageCheck
End_Procedure
Procedure_Section Body as CustBody
    Send Update_Status Customer.Name // update the status panel
    Print Customer.Number
    Print Customer.Name
    OutPut_PageCheck
End_Procedure
Procedure_Section Page_Bottom as Footer
    OutPut_PageCheck
End_Procedure
End_Object

Within the report view, the report would be started by creating the following procedure:

Procedure StartReport
    Integer ToScreen
    String FileNme
    Get Print_to_Screen_State to ToScreen
    If ToScreen Begin
        Make_Temp_File "TXT" FileNme
        Move (".\" -FileNme) to FileNme
        Set Output_Device_Name to FileNme
    End
    Else ;
        Set Output_Device_Name to "WinLst:"
        Send run_report
    If ToScreen Begin
        RunProgram background "NotePad" FileNme
        EraseFile FileNme
    End
End_Procedure

Important Notes

Some things to note about this sample:

  • This report should be placed inside a ReportView or ReportPanel. This source may be directly pasted into the container or it may be placed in its own source file and included in the program (with the #INCLUDE command).
  • Output lines are created by creating embedded named "images" (e.g., CustBody). Each image contains display fields (e.g., ____). These fields are filled with the print command and then displayed with the Output_PageCheck command.
  • It is assumed that the report will be generated to a file or a print file. It is up to you to define this file by setting the report view’s Output_Device_Name property. It is also up to you to display or print the file.
  • If a report view contains a single report, the report may be run simply by sending the message Run_Report to the view.
  • Each part of a report is defined by the Procedure_Section command. These sections are procedures that are called at the appropriate time of the report process.
  • In the body section, the message Update_Status is used to display progress to a status panel. The status panel will appear when the report starts, show progress, allow the user to cancel the report, and will disappear when the report is complete.
  • If the status panel’s cancel button is selected, a prompt will appear asking the user if the report should be canceled.
  • If an error occurs during the report, an error message will be displayed. Then, another prompt will appear asking the user if the report should be stopped.