This new function contains the report driver, together with the logic to determine
        whether the user has attempted to interrupt the report.
Function 
cust_report
            (
custreport2.4gl):
21 FUNCTION cust_report()
22
23 DEFINE pr_custrec RECORD
24       store_num   LIKE customer.store_num,
25       store_name  LIKE customer.store_name,
26       addr        LIKE customer.addr,
27       addr2       LIKE customer.addr2,
28       city        LIKE customer.city,
29       state       LIKE customer.state,
30       zip_code     LIKE customer.zip_code 
31       END RECORD,
32       rec_count, rec_total, 
33       pbar, break_num INTEGER
34
35   LET rec_count = 0     
36   LET rec_total = 0
37   LET pbar = 0
38   LET break_num = 0
39   LET INT_FLAG = FALSE
40
41   SELECT COUNT(*) INTO rec_total FROM customer 
42
43  LET break_num = (rec_total/10)  
44
45   DECLARE custlist CURSOR FOR
46     SELECT store_num, 
47        store_name, 
48        addr, 
49        addr2, 
50        city, 
51        state, 
52        zip_code 53     FROM CUSTOMER    
54      ORDER BY state, city 
55
56   START REPORT cust_list TO FILE "customers.txt"
57   FOREACH custlist INTO pr_custrec.*
58     OUTPUT TO REPORT cust_list(lr_custrec.*)
59     LET rec_count = rec_count+1
60    IF (rec_count MOD break_num)= 0 THEN 
61       LET pbar = pbar+1
62       DISPLAY pbar TO rptbar 
63       CALL ui.Interface.refresh() 
64      IF (INT_FLAG) THEN
65        EXIT FOREACH
66       END IF
67     END IF
68   END FOREACH
69
70   IF (INT_FLAG) THEN
71    LET INT_FLAG = FALSE
72    MESSAGE "Report cancelled"
73  ELSE
74     FINISH REPORT cust_list 
75     MESSAGE "Report finished"  
76  END IF
77
78 END FUNCTION
 
Note: 
- Lines 23 thru 31 now define the pr_custrec record in this
                    function.
 
- Lines 32 thru 33 define some additional variables.
 
- Lines 35 thru 39 initialize the local variables.
 
- Line 38 sets INT_FLAG to
                        FALSE.
 
- Line 41 uses an embedded SQL statement to retrieve the
                    count of the rows in the customer table and stores it in the
                    variable rec_total.
 
- Line 43 calculates the value of
                        break_num based on the maximum value of the
                        PROGRESSBAR, which is set at 10. After
                        break_num rows have been processed, the program will
                    increment the PROGRESSBAR. The front end cannot handle
                    interruption requests properly if the display generates a lot of network
                    traffic, so we do not recommend refreshing the AUI and checking
                        INT_FLAG after every row.
 
- Lines 45 thru 54 declare the custlist cursor for the
                        customer table.
 
- Line 56 starts the report, sending the output to the
                    file custout.
 
- Lines 58 thru 68 contain the FOREACH statement to output each
                    record to the same report cust_list used in the previous
                    example.
 
- Line 59 increments rec_count to keep
                    track of how many records have been output to the report.
 
- Line 60 tests whether a break point has been reached,
                    using the MOD (Modulus) function.
 
- Line 61 If a break point has been reached, the value
                    of pbar is incremented.
 
- Line 62 The pbar value is displayed
                    to the rptbar
                    PROGRESSBAR form field.
 
- Line 63 The front end is synced with the current AUI tree.
 
- Line 64 thru 66 The value of INT_FLAG is checked to see
                    whether the user has interrupted the program. If so, the
                        FOREACH loop is exited prematurely.
 
- Lines 70 thru 76 test INT_FLAG again and display a message
                    indicating whether the report finished or was interrupted. If the user did not
                    interrupt the report, the FINISH REPORT statement is
                    executed.