Adding a Table of Contents to the CUST.SQR Sample Program
The following program is based on cust.sqr, which is located in the SAMPLE (or SAMPLEW) directory. The program identifies the table of contents with the specific name of cust_toc. The dot leader is turned on. Indentation is set to 3. One table of contents level is set by using the LEVEL=1 argument or the TOC-ENTRY command. The BEFORE-PAGE and AFTER-TOC arguments of the DECLARE-TOC command are used to print simple messages here.
Table of Contents Sample Program 1
Consider this sample program:
begin-setup
declare-toc cust_toc
for-reports=(all)
dot-leader=yes
indentation=3
after-toc=after_toc
before-page=before_page
end-declare
end-setup
begin-program
do main
end-program
begin-procedure after_toc
position (+1,1)
print 'After TOC' () bold
position (+1,1)
end-procedure
begin-procedure before_page
position (+1,1)
print 'Before Page' () bold
position (+1,1)
end-procedure
begin-procedure main
begin-select
print 'Customer Info' ()
print '-' (+1,1,62) Fill
name (+1,1,25)
toc-entry text = &name level = 1
cust_num (,35,30)
city (+1,1,16)
state (,17,2)
phone (+1,1,15) edit (xxx)bxxx-xxxx
position (+2,1)
from customers
order by name
end-select
end-procedure ! main
begin-heading 3
print $current-date (1,1) Edit 'DD-MON-YYYY'
page-number (1,69) 'Page '
end-heading
Table of Contents Sample Program 2
The following program is also based on cust.sqr. It is similar to the previous program but declares two table of contents levels. This program also creates headings and footings that are specific to the table of contents. The FOR-TOCS argument of the BEGIN-HEADING and BEGIN-FOOTING commands enable you to specify, by name, the table of contents to which the particular heading or footing section applies. If the program is generating multiple reports with multiple tables of contents, then you can apply unique or common headings and footings to different reports and tables of contents. The table of contents heading of this program prints Table of Contents and the page number. The page numbers in the table of contents print as roman numerals. The table of contents footing prints Company Confidential.
begin-setup
declare-report cust
end-declare
declare-toc cust_toc
for-reports=(cust)
dot-leader=yes
indentation=3
after-toc=after_toc
before-page=before_page
end-declare
declare-variable
integer #num_toc
integer #num_page
end-declare
end-setup
begin-program
use-report cust
do main
end-program
begin-procedure after_toc
position (+1,1)
print 'After TOC' () bold
position (+1,1)
end-procedure
begin-procedure before_page
position (+1,1)
print 'Before Page' () bold
position (+1,1)
end-procedure
begin-procedure main
begin-select
print 'Customer Info' ()
print '-' (+1,1,62) Fill
name (+1,1,25)
toc-entry text = &name level = 1
cust_num (,35,30)
city (+1,1,16)
state (,17,2)
phone (+1,1,15) edit (xxx)bxxx-xxxx
position (+2,1)
do orders(&cust_num)
position (+2,1)
from customers
order by name
end-select
end-procedure ! main
begin-procedure orders (#cust_num)
let #any = 0
begin-select
if not #any
print 'Orders Booked' (+2,10)
print '-------------' (+1,10)
let #any = 1
end-if
b.order_num
b.product_code
order_date (+1,10,20) Edit 'DD-MON-YYYY'
description (,+1,20)
toc-entry text = &description level=2c.price * b.quantity
(,+1,13) Edit $$$$,$$0.99
from orders a, ordlines b, products c
where a.order_num = b.order_num
and b.product_code = c.product_code
and a.cust_num = #cust_num
order by b.order_num, b.product_code
end-select
end-procedure ! orders
begin-footing 3
for-tocs=(cust_toc)
print 'Company Confidential' (1,1,0) center
print $current-date (1,1) Edit 'DD-MON-YYYY'
end-footing
begin-heading 3
for-tocs=(cust_toc)
print 'Table of Contents' (1,1) bold center
let $page = roman(#page-count)
print 'Page ' (1,69)
print $page ()
end-heading
begin-heading 3
print $current-date (1,1) Edit 'DD-MON-YYYY'
page-number (1,69) 'Page '
end-heading