The cust_report function
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 FUNCTIONNote: 
- Lines 
23thru31now define thepr_custrecrecord in this function. - Lines 
32thru33define some additional variables. - Lines 
35thru39initialize the local variables. - Line 
38setsINT_FLAGtoFALSE. - Line 
41uses an embedded SQL statement to retrieve the count of the rows in thecustomertable and stores it in the variablerec_total. - Line 
43calculates the value ofbreak_numbased on the maximum value of thePROGRESSBAR, which is set at 10. Afterbreak_numrows have been processed, the program will increment thePROGRESSBAR. 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 checkingINT_FLAGafter every row. - Lines 
45thru54declare thecustlistcursor for thecustomertable. - Line 
56starts the report, sending the output to the file custout. - Lines 
58thru68contain theFOREACHstatement to output each record to the same reportcust_listused in the previous example. - Line 
59incrementsrec_countto keep track of how many records have been output to the report. - Line 
60tests whether a break point has been reached, using theMOD(Modulus) function. - Line 
61If a break point has been reached, the value ofpbaris incremented. - Line 
62Thepbarvalue is displayed to therptbarPROGRESSBARform field. - Line 
63The front end is synced with the current AUI tree. - Line 
64thru66The value ofINT_FLAGis checked to see whether the user has interrupted the program. If so, theFOREACHloop is exited prematurely. - Lines 
70thru76testINT_FLAGagain and display a message indicating whether the report finished or was interrupted. If the user did not interrupt the report, theFINISH REPORTstatement is executed.