The sample report, Percent.frx, shows one way to calculate and display values at the beginning report before all the records from the record source have been printed. This sample report prints a percentage based on a total that is usually calculated and printed at the end of a report.
The sample report uses the tables, EMPLOYEE and ORDERS, in its Data Environment. A public variable and expressions using the ORDER_AMT field are used to calculate the percentages.
To sort the data appropriately for the group defined in the report, the Order property on Cursor1 is set to the EMP_ID index.
The public variable, nTotalSales, defined in the Init event of Cursor2, stores the total for all orders. The variable is declared public to make it visible beyond the Cursor2 Init code.
A field control in the Group Footer band calculates and displays the percentage for each employee using the following expression:
STR(INT((emp_total / nTotalSales)*100)) + " " + "%"
A field control in the Summary band calculates and displays the total percentage for all employees using the following expression:
STR(INT((nTotalSales / nTotalSales)*100)) + " " + "%"