Syntax
ONCHANGE variable AS literal FOOTING frame_name [ AT line_number ] HEADING frame_name [ AT line_number ] [ < routine_call> ] <routine_call> := routine variable GIVING variable
Parameters
OnChange can be abbreviated as OCH.
variable
The controlling variable.
AS literal
Optional clause to provide a user-defined value for Glb.Change. It is a string expression with a maximum length of 30 characters. Glb.Change holds the value of the 'As' qualifier string whose value has changed. Glb.Change contains spaces until a change in value occurs. You can test against Glb.Change to find out which variable triggered the OnChange action.
FOOTING frame_name
FOOTING can be abbreviated as FTG. Specifies a report frame as the footer.
AT line_number (first)
Specifies the line number to start the report footer.
HEADING frame_name
HEADING can be abbreviated as HDG. Specifies the qualifier, a report frame, as the header.
AT line_number(second)
Specifies the line number to start the report header.
routine_call
A call to a statistical routine. Refer to Routine Call for more information.
routine variable
The source variable used by the statistical routine as the basis of its computation.
GIVING variable
Directs the result of the computation to the specified variable.
Description
The OnChange logical command specifies control breaks in reports. A footer and a header are invoked whenever the value of the controlling variable changes. This variable can be any persistent or non-persistent report attribute.
Footers and headers are report frames. Typically the footer prints a summary, such as a subtotal, and the header prints a title corresponding to the new value of the variable. The header can also be used to initialize non-persistent variables associated with the report.
The header is invoked before the first record, and the footer is invoked after the last record. The final footer is printed immediately after the end of all the current loops, and before any following logic statements.
The Glb.Change built-in segment attribute is set to the name of the variable whose value has changed as specified with the ‘As’ option. The Glb.Change built-in segment attribute is set to spaces until a change in value occurs.
The OnChange logic command can be used in association with standard statistical routines. Refer to Routine Call for more information.
Variable values
After the value of the controlling variable changes, values of attributes in the footer are from the prior database record (the record with the previous value of the controlling variable). However, references to attributes in the database (for example, Cust.Name) access the new record (the record with the new value of the controlling variable). Consequently, this also means that any frames called from the footer use the new value.
Update the footer with the new value by moving the value to the specified variable after the relevant database access logic command (for example, ForEach Statement, or the Determine Variants or LookUp logic command variants).
Values of variables in the header are from the new record.
Grouping OnChanges
Multiple OnChange logic statements can be grouped within a logic loop to form a hierarchy of control breaks (for example, customer within branch).
When multiple levels of control breaks are specified, the hierarchy of levels is given by the order in which the commands are coded. The first is the highest level (associated with the first header and the last footer).
Restrictions
The OnChange logic command can only be used within a loop in the Main method or in the frame methods of a report. For example, the OnChange logic command can be used within the logic commands, such as Loop or ForEach. It is not supported with sleeping reports.
Examples
Example 1
Determine Actual Accounts OnChange Cust.Branch As "CustBranch" Footing Frame05 Heading Frame01 OnChange Cust.CustNo As "CustNumber" Footing Frame04 Heading Frame02 Frame03.Print() End
This results in the frames being invoked in the following sequence:
Frame | Description | Comments |
---|---|---|
Frame01 | Branch heading |
|
Frame02 | Customer heading |
|
Frame03 | Customer account record | Multiple customer account records until Cust.CustNo or Cust.Branch changes |
Frame04 | Customer summary | Cust.CustNo changes in value. Glb.Change has the value of "CustNumber" |
Frame02 | Customer heading |
|
Frame03 | Customer account record | Multiple customer account records until Cust.Branch changes |
Frame04 | Customer summary | Cust.CustNo changes in value. Glb.Change has the value of "CustNumber" |
Frame05 | Branch summary | Cust.Branch changes in value. Glb.Change has the value of "CustBranch" |
Frame01 | Branch heading | Cust.Branch changes in value. Glb.Change has the value of "CustBranch" |
Frame02 | Customer heading | Cust.CustNo changes in value. Glb.Change has the value of "CustNumber" |
etc… |
|
|
Example 2
An employee listing by JobType within Dept, giving the numbers of persons, average salary, and standard deviation of salary, could be expressed as follows:
Determine Actual Employees.DeptJobs() : EmpNumber, AvSalary, and StDevSalary are members of Frame42. OnChange Employees.Dept As "EmployeesDept" Footing Frame42 Heading Frame40 \ Count Employees.EmpNo Giving EmpNumber \ Average Employees.Salary Giving AvSalary \ StdDeviation Employees.Salary Giving StDevSalary : JopEmps, JobSalary, and JobStDevSalary are members of Frame42. OnChange Employees.JobType As "EmployeesJobType" Footing Frame32 Heading Frame30 \ Count Employees.EmpNo Giving JopEmps \ Average Employees.Salary Giving JobSalary \ StdDeviation Employees.Salary Giving JobStDevSalary \ : Employee details Frame10.Print() End