Understanding the Sample Program for Simple Tabular Reports

The following sample program produces a simple tabular report, similar to the one shown in the topic “Selecting Data from the Database.”

Program ex12a.sqr
begin-setup
 declare-layout default
 end-declare
end-setup
begin-program
 do main
end-program
begin-procedure main
begin-select
name  (,1,30)
city  (,+1,16)
state (,+1,5)
tot   (,+1,11) edit 99999999.99
 next-listing no-advance need=1
 let #grand_total = #grand_total + &tot
from customers
end-select
print '-' (,55,11) fill
print 'Grand Total' (+1,40)
print #grand_total (,55,11) edit 99999999.99
end-procedure ! main
begin-heading 5
 print $current-date (1,1) Edit 'DD-MON-YYYY'
 page-number (1,60) 'Page ' 
 print 'Name'   (3,1)
 print 'City'   (,32)
 print 'State'  (,49)
 print 'Total'  (,61)
 print '-'      (4,1,65) fill
end-heading

The SETUP section contains a DECLARE-LAYOUT command that specifies the default layout without defining any options. The purpose of specifying the default layout is to use its margin settings, which are defined as 1/2 inch. Without DECLARE-LAYOUT, the report would have no margins.

Note the PRINT command with the FILL option. This command produces dashed lines, which is a simple way to draw lines for a report that is printed on a line printer. On a graphical printer, however, you can draw solid lines.

The following is the output for program ex12a.sqr:

    06-JUN-04                                                 Page 1
     
     Name                           City             State     Total
     ---------------------------------------------------------------
     
     Gregory Stonehaven             Everretsville    OH        39.00
     John Conway                    New York         NY        42.00
     Eliot Richards                 Queens           NY        30.00
     Isaiah J Schwartz and Company  Zanesville       OH        33.00
     Harold Alexander Fink          Davenport        IN        36.00
     Harriet Bailey                 Mamaroneck       NY        21.00
     Clair Butterfield              Teaneck          NJ        24.00
     Quentin Fields                 Cleveland        OH        27.00
     Jerry's Junkyard Specialties   Frogline         NH        12.00
     Kate's Out of Date Dress Shop  New York         NY        15.00
     Sam Johnson                    Bell Harbor      MI        18.00
     Joe Smith and Company          Big Falls        NM         3.00
     Corks and Bottles, Inc.        New York         NY         6.00
     Harry's Landmark Diner         Miningville      IN         9.00
                                                           ---------
                                            Grand Total       315.00

See Adding Graphics.