Understanding the Sample Program for Listing and Printing Data

Here is a sample program that selects data from the database and prints it in columns:

Program ex3a.sqr
begin-program
   do list_customers
end-program
begin-heading 4
   print 'Customer Listing' (1) center
   print 'Name' (3,1)
   print 'City' (,32)
   print 'State' (,49)
   print 'Phone' (,55)
end-heading
begin-footing 1
   ! Print "Page n of m" in the footing
   page-number (1,1) 'Page '
   last-page   () ' of '
end-footing
begin-procedure list_customers
begin-select
name (,1)
city (,32)
state (,49)
phone (,55)
   position (+1)  ! Advance to the next line
from customers
end-select
end-procedure ! list_customers

The output for the ex3a.sqr program is:

                       Customer Listing

Name                           City            State  Phone
Gregory Stonehaven             Everretsville    OH    2165553109
John Conway                    New York         NY    2125552311
Eliot Richards                 Queens           NY    2125554285
Isaiah J Schwartz and Company  Zanesville       OH    5185559813
Harold Alexander Fink          Davenport        IN    3015553645
Harriet Bailey                 Mamaroneck       NY    9145550144
Clair Butterfield              Teaneck          NJ    2015559901
Quentin Fields                 Cleveland        OH    2165553341
Jerry's Junkyard Specialties   Frogline         NH    6125552877
Kate's Out of Date Dress Shop  New York         NY    2125559000
Sam Johnson                    Bell Harbor      MI    3135556732
Joe Smith and Company          Big Falls        NM    8085552124
Corks and Bottles, Inc.        New York         NY    2125550021
Harry's Landmark Diner         Miningville      IN    3175550948
Page 1 of 1

The PROGRAM section contains a single DO command, which invokes the list_customers procedure.

In SQR language, a procedure is a group of commands that is performed one after the other, as a procedure (or subroutine) is in other programming languages. A DO command invokes a procedure.

Break your program logic into procedures and keep the PROGRAM section small. It should normally contain a few DO commands for the main components of your report.

The HEADING section creates headings for the report columns. In this example, four lines are reserved for the heading:

begin-heading 4
   print 'Customer Listing' (1) center
   print 'Name' (3,1)
   print 'City' (,32)
   print 'State' (,49)
   print 'Phone' (,55)
end-heading

The Customer Listing title is printed on line 1. Line 2 is left blank. The first column heading, Name, is positioned at line 3 of the heading, in character position 1. The rest of the column heading commands omit the line numbers in their positions and are set by default to the current line. Line 4 of the heading is left blank.

In this sample program, the footing is the same as the one in the previous sample program.