Creating a Summary Report This technote explains how to create a custom report that prints only the summary information of a report. The scenario used here is based on the Customer and Order files found in the Samples/Stock directory. The report prints the number of orders by state as well as the number of orders for a particular month. The problem is when a calculation is placed in the after group band the calculation includes all the records in the body. You cannot specify a sub-filter to calculate only those records with a certain value. For example, you have a field represents the department where each employee works and you want a count of employees in Marketing, Publishing and Human Resources. A count cannot be based on the value in the department field. If there are 100 employees, all of the counts will equal 100. To calculated based on a field value, some simple modifications to the report program file are required. Creating the report In the Report Designer, open the Customer and Orders files. Define a group on State. CUSTOMER. Be sure to select Before and After Groups. In the Before group, place the State field. In the report body, place a field from the Order file. Remember this field will not print in the final output, but is required to establish the link so the calculations are not 0. In the After group, place a calculated field: tot%. The calculation for this is a count on OrderDate.ORDERS. In a field calculation, it is enough to select COUNT; it does not have to appear in the formula box. If you want your calculation to include blank fields, select ALL. Place another calculated field in the After group: cnt%. This variable is calculated in the report, program so don't do anything to it now. It represents the number of orders where date is in the month of January. Define the file links. You may also define a page footer and place a calculated field there (total%). Save the report. This creates the .SBV and .SBP files. Load the program file into the Program Editor and make the changes shown below. Code changes are in bold text. Run the program. SUB main() CALL SUMRPT() END SUB SUB SUMRPT() REPORT USING "SUMRPT" AFTER REPORT SET REPORT PAGE "F_REPORT" OUTPUT REPORT PAGE END REPORT HEADING SET REPORT PAGE "H_PAGE" OUTPUT REPORT PAGE END HEADING FOOTING 1 SET REPORT PAGE "F_PAGE" OUTPUT REPORT PAGE END FOOTING GROUP State.CUSTOMER,OrderNo.ORDER AS "tot%" BEFORE GROUP State.CUSTOMER SET REPORT PAGE "H_State.CUST002" OUTPUT REPORT PAGE END GROUP REM The Set Report Page and Output Report Page statements here cause the summary variables in REM the after group information to be printed. Then the report footer total is incremented. This REM could be done in other areas just as well. The cnt% variable is set back to 0 and ready to REM count for the next group of records. AFTER GROUP State.CUSTOMER SET REPORT PAGE "F_State.CUST002" OUTPUT REPORT PAGE total% = total% + cnt% cnt% = 0 END GROUP REM The After Select processes each record in the body of the report. Remarking out the Set REM Report Page and Output Report Page statement cause the body information not to be printed. REM Since each record passes through here it gives us the opportunity to check for a specific value REM and then act on it. For example if the month of OrderDate is 1 (January) then increment the REM counter. AFTER SELECT REM SET REPORT PAGE "F_SELECT" REM OUTPUT REPORT PAGE IF MONTH (OrderDate.ORDER) = 1 THEN cnt% = cnt% + 1 END SELECT SET QUERY OFF SET QUERY LOCK OFF SELECT ; WHERE CustomerNo.CUSTOMER = CustomerNo.ORDER TO WINDOW END SUB Some background on custom reports When a custom report is saved in the Report Designer, two files are created for the report design. A report can be run by either running the .SBP program or opening the .SBV file. filename.SBV: contains information about the objects used in the report, and the way they are laid out. filename.SBP: contains the SBL program that produces the report. This .SBP program uses the information in the .SBV file to select data from the database files and formats the report. The lay out of a report is in bands. Below is a brief description of what some of these bands do. This helps in understanding how to modify the report program file. The BEFORE SELECT and AFTER SELECT carry out tasks before or after the program prints each row. The AFTER SELECT section outputs the record data. This is where a majority of our work is done. The BEFORE GROUP and AFTER GROUP define any processing that occurs when a report group changes. If the value of any group has changed from the previous record, Superbase then: 1. Outputs the report data 2. Triggers the most senior AFTER GROUP section for the groups that have changed. 3. Triggers the most senior BEFORE GROUP section for the groups that have changed. 4. Selects the next record. Notice that one of the first statements in the .SBP program is REPORT USING "TEST" This statement is referring to the .SBV file. You cannot look at a .SBV file, but you can save it as a .SBP file to get an idea of how it works. To do this, choose Save As / Program from the Report Designer menu. Be careful not to give it the same name as your current report since this overwrites the existing .SBV file and any modifications you may have made. For more information on this topic refer to technote number 4040, "Debugging Custom Reports". Hint: Modifying the report name in the REPORT USING statement will allow you to go back and modify the report objects without having to retype all your program changes. Program: Superbase Versions: 2.0 Date: September 9, 1993 D Date: