Fetching report data from a data file

You can get the report data from a data file - one created by the BDL UNLOAD statement, for example.

This example uses the OrderReport.unl file in the GRW demo Reports.

The only change to the MAIN program block would be the call to the runReportFromFile function in line 26.
MAIN

   DEFINE handler om.SaxDocumentHandler -- report handler

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

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

END MAIN

The function runReportFromFile replaces the runReportFromDatabase function as the Report Driver. It uses the unload file OrderReport.unl to provide the data for the report.

  • Defines ch as a variable of type base.channel. The BDL Channel class provides read/write access to files.
  • Defines the variable dataFile to specify the unload file containing the data.
  • Assigns the report name to the dataFile variable.
  • Creates the ch channel object.
  • opens the channel to the data file OrderReport.unl in read (r) mode.
  • The WHILE statement reads a line from the data file, providing the variable list enclosed in brackets. The line is output to the REPORT program block. The statement terminates when all the lines have been read.
  • Closes the channel.
 FUNCTION runReportFromFile(handler)
   DEFINE
        orderline OrderType,
        handler om.SaxDocumentHandler,
        ch base.channel,    -- definition of channel object
        dataFile String       -- file containing report data

   LET dataFile = "./OrderReport.unl"
   LET ch = base.Channel.create()
   CALL ch.openFile(dataFile,"r") 

   START REPORT report_all_orders TO XML HANDLER handler 
   WHILE ch.read([orderline.*])
      OUTPUT TO REPORT report_all_orders(orderline.*)
   END WHILE
   FINISH REPORT report_all_orders

   CALL ch.close()
 END FUNCTION