Writing Printer-Independent Reports

This chapter provides an overview of printer-independent reports and discusses the sample program for selecting the printer type at runtime.

Click to jump to parent topicUnderstanding Printer-Independent Reports

To create a printer-independent report, you must write a program that avoids using any characteristics that are unique to a specific printer. Although complete printer independence may be too restrictive, make your report as printer-independent as you can by following these guidelines:

If your report is printer-neutral and does not specify a printer, you can specify the printer at runtime in two ways.

The first method is to use the -PRINTER:xx command-line flag, which specifies the output type for your report. Use the following commands:

If you are using the system shell, enter this command on the command line:

sqr test ​username/password ​-printer:ps

Note. Currently, PRINTER:WP sends output to the default Microsoft Windows printer. To specify a nondefault Microsoft Windows printer, enter the following command: -PRINTER:WP:{Printer Name}. The {Printer Name} is the name assigned to your printer. For example, to send output to a Microsoft Windows printer named NewPrinter, you would use -PRINTER:WP:NewPrinter. If your printer name has spaces, enclose the entire command in double quotes.

The second method of specifying the printer type is by using the USE-PRINTER-TYPE command.

See USE-PRINTER-TYPE.

Click to jump to parent topicReviewing the Sample Program for Selecting the Printer Type at Runtime

In the following example, the PROGRAM section prompts the user to select the printer type at runtime. The relevant lines are shown like this:

begin-program input $p 'Printer type' ! Prompt user for printer type let $p = lower($p) ! Convert type to lowercase evaluate $p ! Case statement when = 'hp' when = 'hplaserjet' ! HP LaserJet ​use-printer-type hp ​break when = 'lp' when = 'lineprinter' ! Line Printer ​use-printer-type lp ​break when = 'ps' when = 'postscript' ! PostScript ​use-printer-type ps ​break when-other display 'Invalid printer type.' stop end-evaluate do list_customers end-program

In this code, the INPUT command prompts the user to enter the printer type. Because the USE-PRINTER-TYPE command does not accept a variable as an argument, the EVALUATE command is used to test for the six possible values and set the printer type accordingly.

The EVALUATE command is similar to a switch statement in the C language. It compares a variable to multiple constants and carries out the appropriate code.