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 FUNCTION
Note:
- Lines
23
thru31
now define thepr_custrec
record in this function. - Lines
32
thru33
define some additional variables. - Lines
35
thru39
initialize the local variables. - Line
38
setsINT_FLAG
toFALSE
. - Line
41
uses an embedded SQL statement to retrieve the count of the rows in thecustomer
table and stores it in the variablerec_total
. - Line
43
calculates the value ofbreak_num
based on the maximum value of thePROGRESSBAR
, which is set at 10. Afterbreak_num
rows 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_FLAG
after every row. - Lines
45
thru54
declare thecustlist
cursor for thecustomer
table. - Line
56
starts the report, sending the output to the file custout. - Lines
58
thru68
contain theFOREACH
statement to output each record to the same reportcust_list
used in the previous example. - Line
59
incrementsrec_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 theMOD
(Modulus) function. - Line
61
If a break point has been reached, the value ofpbar
is incremented. - Line
62
Thepbar
value is displayed to therptbar
PROGRESSBAR
form field. - Line
63
The front end is synced with the current AUI tree. - Line
64
thru66
The value ofINT_FLAG
is checked to see whether the user has interrupted the program. If so, theFOREACH
loop is exited prematurely. - Lines
70
thru76
testINT_FLAG
again and display a message indicating whether the report finished or was interrupted. If the user did not interrupt the report, theFINISH REPORT
statement is executed.