Re: different report length
Posted in 1994
Peter Schubert <100043.1556@CompuServe.COM> writes: >We need diffent report length on unknown printers. >(e.g. Lineprinter Length 72, Laserprinter Length 66 ...) >Is there a way to use variables for the PAGE LENGTH parameter ??? No, BUT ... Below are two attacks I've made concerning using a single REPORT function break at different page lengths. The first is a complete program and uses PAGE LENGTH 1 and a lot of duplicate code in each report control block to handle page breaks. As a demo, it handles either 24 or 60 page output (for screen or printer output, natch) The second is a REPORT function from an actual report I wrote last week for a client that wanted the report to go to either legal or standard paper (78 or 66 lines, on this system). It's not as complete as the first, and doesn't show how to handle page footers, although I'm sure it wold be doable with a bit of duplicate code and LINENO testing. It uses the idea of setting PAGE LENGTH to the highest desired number and TOP OF PAGE "^L", which is used to send a top-of-page signal when breaking pages rather than the ole' Informix standard of repeated blank lines to fill out the pages. I hope it's commented well enough to be of use. And if Walt is watching, he should feel free to add these to the repository. ======================================================================= Dennis J. Pimple dennisp@informix.com Opinions expressed Senior Consultant -------------------- are mine, and do not Informix Software Inc Voice: 303-850-0210 necessarily reflect Denver Colorado USA Fax: 303-779-4025 those of my employer. -------------------- CUT HERE FOR scr_prt.4gl ------------------------- ########### # INFORMIX PROFESSIONAL SERVICES ####### # ## Denver, Colorado ###### # ### ================================================== ##### # #### File: %M% SCCS: %I% %P% #### # ##### Program: scr_prt.4go ### # ###### Client: Example ## # ####### Author: Dennis J Pimple # ########### Date: %G% %U% # Example of how to use the same REPORT function to run to either # screen or printer, with appropriate page breaks. # The general approach we take is to handle PAGE HEADERs & TRAILERs # in the ON EVERY ROW section of the REPORT, to avoid any forced page # breaks. This example will output 60-line pages to a printer, # or 23-line pages to a screen (70 lines of report output) MAIN DEFINE outpt CHAR(1) # Screen/Printer DEFINE x SMALLINT # Loop counter DEFINE y SMALLINT # Loop counter CLEAR SCREEN LET outpt = NULL WHILE outpt IS NULL PROMPT "Run to Screen or Printer (S/P)? " FOR CHAR outpt LET outpt = UPSHIFT(outpt) IF outpt IS NULL OR outpt NOT MATCHES "[SP]" THEN ERROR "Type S, P, or INTERRUPT to quit" LET outpt = NULL END IF END WHILE IF outpt = "P" THEN START REPORT rpt_scr_ptr TO PRINTER ELSE START REPORT rpt_scr_ptr TO PIPE " pg" END IF FOR x = 1 TO 10 FOR y = 1 TO 7 OUTPUT TO REPORT rpt_scr_ptr(outpt, x, y) END FOR END FOR FINISH REPORT rpt_scr_ptr END MAIN REPORT rpt_scr_ptr(outpt, x, y) DEFINE outpt CHAR(1) # File or Printer DEFINE x SMALLINT DEFINE y SMALLINT DEFINE pglgth SMALLINT # Page Length DEFINE pgno SMALLINT # Page Number (instead of PAGENO) DEFINE lnno SMALLINT # Line Number (instead of LINENO) DEFINE tm SMALLINT # Top Margin DEFINE bm SMALLINT # Bottom Margin DEFINE pt SMALLINT # Number of lines for Page Trailer DEFINE lastln SMALLINT # Last line to print on each page: # pglgth - bm - pt # set the margins and page length to minimum, # because we'll handle all that in the body of the report OUTPUT TOP MARGIN 0 BOTTOM MARGIN 0 PAGE LENGTH 1 # for my purposes, I'm going to control the LEFT MARGIN # in the PRINT statements as well, but this isn't required LEFT MARGIN 0 # we're going to break by group on x, so inform the report that # x is already sorted. ORDER EXTERNAL BY x FORMAT FIRST PAGE HEADER # use this control block to initialize variables IF outpt = "S" THEN # need to check your machine's implementation of "pg" command, # if you're using it. I found that on some machines/termtypes # it outputs 23/lines/screen, and on others it's 24. # Whatever it is, set pglgth to 1 less than it displays, # because "pg" displays bottom line of one screen as the top # line of the next, so we really have 1 line less than what's # available in your implementation of "pg" for display. LET pglgth = 22 # Also, since on the first page of the report the 1st line is # displayed only once (no previous screen shown), we'll print # an extra blank line at the top of page 1 to align everything # properly (see code below). ELSE # I'm testing on a laser printer that prints 60 lines/page LET pglgth = 60 END IF # set the top & bottom margin # they, too can be different for screen/printer, # although of course they don't have to be IF outpt = "S" THEN LET tm = 0 # WARNING: Make your bm at least 1, # because "pg" gets confused if not. LET bm = 1 ELSE LET tm = 3 LET bm = 3 END IF # set the number of lines in your page trailer LET pt = 2 # calculate the page line we're going to print the body of the report on LET lastln = pglgth - bm - pt LET pgno = 0 LET lnno = 0 BEFORE GROUP OF x # a lot of the code in BEFORE GROUP OF and AFTER GROUP OF are cloned # from the ON EVERY ROW. This is a pain, but necessary. We can't just # CALL functions for the duplicate code, because a PRINT statement has # to be in the REPORT function itself. IF lnno = 0 THEN # print the top margin IF tm > 0 THEN FOR lnno = 1 TO tm PRINT "" END FOR END IF LET lnno = tm # NOTICE: if using "more" in your "OUTPUT TO PIPE" command, # remove the IF block below. "more" doesn't require the extra # line on the first page. IF outpt = "S" AND pgno = 0 THEN # this is the first page, so we need to print the extra # blank line referred to in the FIRST PAGE HEADER PRINT "" END IF # increment the page counter LET pgno = pgno + 1 # print the page header PRINT "PAGE HEADER OF REPORT: ", TODAY USING "mm/dd/yyyy" PRINT "" LET lnno = lnno + 2 END IF # make sure we have room for the group header # + at least 2 lines of data + 3 lines for group trailer IF lnno > (lastln - 2 - 3) THEN # close off this page WHILE lnno < lastln PRINT "" LET lnno = lnno + 1 END WHILE # print the page trailer PRINT "" PRINT "