The Report Driver
The Report Driver for this example, custreports.4gl defines a
cursor to retrieve customer
table rows sorted by state
,
then city
. The START REPORT
statement initializes the
report and provides destination and page setup information to the Report
Definition.
Report Driver
custreports.4gl:
01
SCHEMA
custdemo
02
03
MAIN
04
DEFINE
pr_custrec RECORD
05
store_num LIKE
customer.store_num,
06
store_name LIKE
customer.store_name,
07
addr LIKE
customer.addr,
08
addr2 LIKE
customer.addr2,
09
city LIKE
customer.city,
10
state LIKE
customer.state,
11
zip_code LIKE
customer.zip_code
12
END RECORD
13
14
CONNECT TO
"custdemo"
15
16
DECLARE
custlist CURSOR FOR
17
SELECT
store_num,
18
store_name,
19
addr,
20
addr2,
21
city,
22
state,
23
zip_code
24
FROM
customer
25
ORDER BY
state, city
26
27
START REPORT
cust_list TO FILE
"customers.txt"
28
WITH LEFT MARGIN
= 5, TOP MARGIN
= 2,
29
BOTTOM MARGIN
= 2
30
31
FOREACH
custlist INTO
pr_custrec.*
32
OUTPUT TO REPORT
cust_list(pr_custrec.*)
33
END FOREACH
34
35
FINISH REPORT
cust_list
36
37
DISCONNECT CURRENT
38
39
END MAIN
Note:
- Lines
04
thru12
define a local program recordpr_custrec
, with a structure like thecustomer
database table. - Line
14
connects to thecustdemo
database. - Lines
16
thru25
define acustlist
cursor to retrieve thecustomer
table data rows, sorted bystate
, thencity
. - Lines
27
thru29
starts theREPORT
program block namedcust_list
, and includes a report destination and page formatting information. - Lines
31
thru33
retrieve the data rows one by one into the program recordpr_custrec
and pass the record to theREPORT
program block. - Line
35
closes the report driver and executes any finalREPORT
control blocks to finish the report. - Line
37
disconnects from thecustdemo
database.