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 MAIN
Note:
  • Lines 04 thru 12 define a local program record pr_custrec, with a structure like the customer database table.
  • Line14 connects to the custdemo database.
  • Lines 16 thru 25 define a custlist cursor to retrieve the customer table data rows, sorted by state, then city.
  • Lines 27 thru29 starts the REPORT program block named cust_list, and includes a report destination and page formatting information.
  • Lines 31 thru 33 retrieve the data rows one by one into the program record pr_custrec and pass the record to the REPORT program block.
  • Line 35 closes the report driver and executes any final REPORT control blocks to finish the report.
  • Line37 disconnects from the custdemo database.