Allowing the user to select output options
Users can choose the format to see the report output.
In the GRW demo program Order Report, this form allows the user to make choices regarding the output:
Figure: Report demo Form
![This figure is a screenshot of the Report demo form.](Images/userconfig.jpg)
This code implements this functionality. The form definition file, Configuration.4fd, is included in the demo files for Reports, the GRW Demo.
The MAIN block of SimpleReport.4gl would change as follows:
- Call a function named select_output that displays the form and returns the user's choices
- Configure the report using the mandatory Reporting API functions plus these additional functions:
- fgl_report_selectDevice - sets the report output device; the parameter is one of: "Printer", "PDF", "Image", "SVG" .
- fgl_report_selectPreview - sets the preview option; the parameter is TRUE (preview) or FALSE (no preview).
MAIN
DEFINE handler om.SaxDocumentHandler, -- report handler
data_file String, -- XML file containing data
report_ok boolean, -- return value from function
r_filename STRING, -- filename of desired report
r_output STRING, -- output format
preview INTEGER -- preview indicator
-- call the mandatory functions that configure the report using the
-- choices made by the user
-- in your new select_output function
CALL select_output() RETURNING r_filename, r_output, preview
IF fgl_report_loadCurrentSettings(r_filename) THEN -- if the file loaded OK
CALL fgl_report_selectDevice(r_output) -- changing default
CALL fgl_report_selectPreview(preview) -- changing default
LET handler = fgl_report_commitCurrentSettings() -- commit changes
ELSE
EXIT PROGRAM
END IF
-- run the report by calling the report driver contained in
-- your function runReportFromDatabase
IF handler IS NOT NULL THEN
CALL runReportFromDatabase()
END IF
END MAIN
select_output - this new function displays a form allowing the user to specify the name of
the report to be run (the name of the 4rp file), the output format, and whether
a preview is preferred.
FUNCTION select_output()
DEFINE
r_output STRING, -- output format option
r_action STRING, -- used to set preview option
r_filename STRING, -- filename of Report Design document (4rp filename)
preview INTEGER -- preview option TRUE/FALSE, to display
-- report in Report Viewer
CLOSE WINDOW SCREEN
OPTIONS INPUT WRAP
-- display form allowing user to select the 4rp filename and output options
OPEN WINDOW f_configuration WITH FORM "Configuration"
LET INT_FLAG=FALSE
LET preview = FALSE
INPUT BY NAME r_filename,r_output,r_action
ON ACTION CANCEL
EXIT PROGRAM
ON ACTION CLOSE
EXIT PROGRAM
END INPUT
CLOSE WINDOW f_configuration
CALL ui.interface.refresh()
-- set preview variable to match output option r_action
IF r_action IS NOT NULL THEN
IF r_action == "preview" THEN
LET preview = TRUE
END IF
END IF
-- return report name (filename of Report Design Document) and output
-- option variables to be used to configure the report engine
RETURN r_filename||"4rp", r_output, preview
END FUNCTION