Use the example code

Use the example code that was generated by the Report Data Wizard.

About this task

You can create a report application using the generated BDL file, or the file can be incorporated as part of a larger application. We recommend that you use a different BDL file to contain the additional code that is required, rather than making changes in the generated file. This allows you to re-execute the Report Data Wizard without risking the loss of your changes.

  1. Create the Report Data Definition file.
    1. Create the rdd file that is used to populate the Data View of the Report Design Document, by executing this from the command line:
      fglcomp --build-rdd <generated_file>.4gl 
    2. Add the resulting <sourcefile>.rdd file to your application files.
  2. Design the report.

    Specify the rdd file on the Data View page. When your design is complete, save the report definition file (4rp) as part of your application. See Designing a Report for additional information about the design process.

  3. Add additional BDL Code to the program.
    1. To configure the report, call the mandatory report API functions, which identify the report definition file and create the XML handler for the report:

      Additional report API functions can be called to change the default output options, if needed.

    2. To connect to the Database, add a CONNECT TO or DATABASE statement to the program.
    3. Call the run_<databasename>_to_handler function (in the file generated by the Report Data Wizard) to execute the report.
  4. Add error handling to the generated wizard code. It is recommended that you call fgl_report_getErrorStatus() after every call to START REPORT, OUTPUT TO REPORT, and FINISH REPORT. For example:
    START REPORT officestore_report TO XML HANDLER handler 
        IF fgl_report_getErrorStatus() THEN           
              DISPLAY "FGL: STOPPING REPORT, msg=\"",fgl_report_getErrorString(),"\""
        END IF 
    FOREACH cur INTO data.*
       OUTPUT TO REPORT officestore_report(data.*)
          IF fgl_report_getErrorStatus() THEN           
                DISPLAY "FGL: STOPPING REPORT, msg=\"",fgl_report_getErrorString(),"\""
                EXIT FOREACH
          END IF 
    FINISH REPORT officestore_report
        IF fgl_report_getErrorStatus() THEN 
              DISPLAY "FGL: STOPPING REPORT, msg=\"",fgl_report_getErrorString(),"\""
        END IF

Example MAIN function

This simple function illustrates the addition of BDL code:


   DEFINE handler om.SaxDocumentHandler -- report handler

   DATABASE officestore --connect to the database

      --call the mandatory functions that configure the report
   IF fgl_report_loadCurrentSettings("myreport.4rp") THEN -- if file loaded OK
     LET handler = fgl_report_commitCurrentSettings()     -- commit the 
                                                          -- file settings

      -- run the report by calling the report driver contained in your 
        -- generated function
   IF handler IS NOT NULL THEN  
     CALL run_officestore_to_handler(handler)