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 REPORTcust_list
36
37 DISCONNECT CURRENT
38
39 END MAINNote:
- Lines
04thru12define a local program recordpr_custrec, with a structure like thecustomerdatabase table. - Line
14connects to thecustdemodatabase. - Lines
16thru25define acustlistcursor to retrieve thecustomertable data rows, sorted bystate, thencity. - Lines
27thru29starts theREPORTprogram block namedcust_list, and includes a report destination and page formatting information. - Lines
31thru33retrieve the data rows one by one into the program recordpr_custrecand pass the record to theREPORTprogram block. - Line
35closes the report driver and executes any finalREPORTcontrol blocks to finish the report. - Line
37disconnects from thecustdemodatabase.