Control-Section
The CONTROL-SECTION defines the conditions for grouping, sub-totaling, and totaling to be used in the REPORT-SECTION.
Line Types
Section titled “Line Types”The following line types are used in the CONTROL-SECTION:
- CBnn
- Control Break
- STnn
- Subtotal
- CTnnA
- Computed Total Accumulate
- CTnnM
- Computed Total (Multiple Accumulators)
- CTnnP
- Computed Total Print
- CTnnE
- Conditional Execution
Conventions
Section titled “Conventions”This section provides information on specifications that can be entered in the CONTROL-SECTION of a report definition. The commands and variables are arranged alphabetically, and the information for each entry is organized in the following way:
FUNCTION
A brief description of the action or purpose of each command or variable.
SYNTAX
An outline of command or variable structure, including syntax and readability options. Parameter choices are detailed directly following the command.
NOTES
Remarks and important information on command or variable syntax and the function of a command or variable in the CONTROL-SECTION.
EXAMPLES
Typical examples of command and variable usage.
Where there is more than one Format for a command, the beginning of each command is shown in boldface letters and the choices are separated by a blank line.
As long as the elements within a command are separated by spaces and fall within the command area of a report, no indentation is required. For readability, the syntax is represented with standard indentation to highlight clauses and options under each command.
Note: For more examples of Report-IV commands, declarations, and variables, see the Sample Reports appendix.
Logical Conditions
Section titled “Logical Conditions”Entries in the CONTROL-SECTION are comprised of a line type, the keyword WHEN followed by a logical condition. A logical condition is at least one value consisting of constants, Data Names, or expressions that interact with relational or logical operators to form either a true or false result.
Two special condition indicators are allowed:
- WHEN Data Name CHANGES
- This condition is met when the current value of the specified Data Name changes from its previous value.
- WHEN EOF
- This condition is met when the end of file has been reached.
EXAMPLES
WHEN CUST-CODE = "0001"WHEN CUST-CODE LIKE "B??Z"WHEN CUST-CODE CHANGESWHEN CUST-CODE(1,2) = "00" OR CUS-STATE CHANGESWHEN REP-CODE = "009" AND YTD-SALES = "200"WHEN EOFSubtotals and Computed Total Lines
Section titled “Subtotals and Computed Total Lines”For subtotals and computed total lines, an additional component of the WHEN command can indicate the items that are being totaled by specifying their Data Names.
Subtotal Registers
Section titled “Subtotal Registers”For subtotals (STnn), the values are accumulated in the subtotal registers for each record that is accessed. When a specific subtotal (STnn) condition is met, subtotal lines, which correspond to that condition
(STnn) in the REPORT-SECTION are printed or executed and the subtotal registers are then cleared.
Subtotals are printed in the REPORT-SECTION using subtotal registers and not Data Names.
Computed Total Registers
Section titled “Computed Total Registers”For computed totals, (CTnn), the values are accumulated only when the accumulate condition is met
(CTnnA or CTnnM). Any Computed Total lines (CTnn) in the REPORT-SECTION area are printed when the print condition is met (CTnnP). This allows different conditions to control printing and accumulating totals. Computed totals are not cleared by either condition, but hold running totals. If necessary, you can reset these totals using commands in the REPORT-SECTION.
Calculated Totals
Section titled “Calculated Totals”Calculated totals, like simple totals, can be specified in Subtotal and Computed Total lines. Mathematical expressions can be specified as well as Data Names.
Control Break
Section titled “Control Break”FUNCTION
The CBnn line allows you to group data based on the logical condition. Control breaks specify when to process the first record following a condition such as a change in data.
SYNTAX
CBnn WHEN condition | Data Name CHANGES- nn
- is a number from 0 through 99.
- condition
- uses valid conditional logic.
- Data Name
- is a valid Data Name.
NOTES
- After adding a CBnn line to the CONTROL-SECTION, press the F1 key to update the report workspace.
- You can specify 100 Control Breaks numbered from 0 through 99.
- The Control Break categorizes or breaks up data based on the specified Data Name in the CONTROL-SECTION. It is used to control levels of reporting.
- To meet the condition specified, the previous record is compared to the current record.
- The control break lines defined here are used on the corresponding CBnn lines in the REPORT-SECTION.
- Data Names must not start closer to the left than the “L” in the ruler line.
EXAMPLES
CONTROL-SECTIONCB01 WHEN INVOICE-NUMBER CHANGES
REPORT-SECTIONCB01 Invoice: XXXXXXD Invoice Line: XXXWhen the value for INVOICE-NUMBER meets the conditional logic, the break occurs and the first record following that change is processed. Each time that INVOICE-NUMBER changes, Report-IV will print the INVOICE-NUMBER.
Subtotal
Section titled “Subtotal”FUNCTION
The STnn line automatically accumulates and clears subtotals on the specified data.
SYNTAX
STnn WHEN condition | Data Name CHANGES;: [,Data Name[Data Name...]: [numeric expression]- nn
- a number between 0 and 99.
- condition
- uses valid conditional logic.
- ;
- separates the conditional logic from the Data Names to be totaled.
- Data Name
- is the data for which a subtotal is registered.
- numeric expression
- is the result of an expression to total.
NOTES
- After adding an STnn line to the CONTROL-SECTION, press the F1 key to update the report workspace.
- You can specify 100 subtotals numbered from 0 through 99.
- To meet the condition specified, the current record is compared to the next record.
- If no condition is specified the default is WHEN EOF (end of file).
- Subtotals will accumulate for each Data Name on the STnn line.
- Subtotal accumulators are cleared prior to processing the record, which caused the subtotal break.
- The subtotal accumulates defined here are used on the corresponding STnn lines in the REPORT-SECTION.
EXAMPLES
CONTROL-SECTIONST01 WHEN REP-CODE CHANGES; ACCTG-COST,: REVENUE-MTD
REPORT-SECTIONST01 Total Cost = $###,###.00ST01 Total Revenue = $###,###.00This will accumulate totals for ACCTG-COST and REVENUE-MTD until the value of REP-CODE changes. At that point, the ST01 lines in the REPORT-SECTION will print and the subtotals will be cleared. Processing will continue with the new record that contains the new value of REP-CODE.
See also STnn in the REPORT-SECTION section of this manual.
Computed Total
Section titled “Computed Total”FUNCTION
The CTnn line accumulates computed totals for the specified data.
Use a : (colon character) as a line type designator for the next line if the commands and/or syntax must continue on the next line.
SYNTAX
CTnnA WHEN condition; |numeric expression: [,Data Name...] [,numeric expression...]
CTnnP WHEN condition
CTnnM WHEN condition; Data Name|expression
CTnnE Thoroughbred Basic syntax- nn
- a number between 0 and 99.
- condition
- uses valid conditional logic.
- ;
- separates the conditional logic from the Data Name.
- Data Name
- is the data for which a total is registered.
- expression
- includes any valid Data Name.
Thoroughbred Basic syntax is any valid Thoroughbred Basic syntax.
NOTES
-
The CTnn line type can take the following forms:
CTnnA Accumulate
CTnnP Print
CTnnM Multiple Accumulators
CTnnE Execute
-
After adding a CTnn line to the CONTROL-SECTION, press the F1 key to update the report work area.
-
You can specify 100 computed total breaks numbered 0 through 99. The numbers cannot be duplicated by the CTnnM and CTnnE lines.
-
The WHEN condition must follow the same syntax rules for a Thoroughbred Basic IF directive, except that no THEN or ELSE is allowed.
-
The WHEN condition can be omitted to select all records.
-
Multiple Data Names can be specified (except for CTnnM) for which computed totals will register.
-
Data names must not start closer to the left than the “L” in the ruler line.
EXAMPLES
CT01A WHEN INVOICE-NUM CHANGES; COMMISS, SALES-AMTCT01P WHEN REP-CODE CHANGESThe CT01A line specifies that when INVOICE-NUM changes, the value of the Data Name COMMISS is added in a computed total register and the value of SALES-AMT is added in a computed total register. The CT01P line specifies that these registered totals will print when the Data Name REP-CODE changes.
See also CTnn in the REPORT-SECTION.
Computed Totals (Multiple Accumulators)
Section titled “Computed Totals (Multiple Accumulators)”FUNCTION
The CTnnM line provides statistics on the specified data by using various accumulators.
SYNTAX
CTnnM WHEN condition|expression[; Data Name]- nn
- a number between 0 and 99.
- condition
- uses valid conditional logic.
- ;
- separates the conditional logic from the expression.
- Data Name
- is the data for which a total is registered.
- expression
- includes any valid Data Names.
NOTES
-
After adding a CTnnM line to the CONTROL-SECTION, press the F1 key to update the report work area.
-
You can specify 100 multiple accumulators numbered from 0 through 99.
-
Only one value (based on a Data Name or a Data Name expression) can be specified with a single CTnnM statement.
-
The WHEN condition can be omitted to select all records, but the semicolon is required.
-
CTnnM generates the following accumulators:
CTnn(0) Count
CTnn(1) Total
CTnn(2) Average [CTnn(1)/CTnn(0)]
CTnn(3) Minimum (low value)
CTnn(4) Maximum (high value)
-
If the Data Name or expression is a string (non-numeric), only the 0 entry or count value is maintained and accessible in the REPORT-SECTION.
EXAMPLES
CT01M WHEN SALES-CODE CHANGES; (BASE-PRICE - ACCTG-COST)CT01P WHEN EOFThe CT01M line specifies that when SALES-CODE changes, the value of the expression
(BASE-PRICE - ACCTG-COST) is added in a computed total register. The CT01P line specifies that these registered totals will print when the end of file (EOF) is reached.
See also CTnn in the REPORT-SECTION.
Conditional Execution
Section titled “Conditional Execution”FUNCTION
Allows you to manipulate data prior to the total logic or to provide additional read logic.
SYNTAX
CTnnE condition; executable code; ...NOTES
-
It supports any report syntax in the CONTROL-SECTION and any Thoroughbred Basic syntax (as long as line numbers are not required). You can have:
CALL publicpgn, x$,y$[ ]CONNECT REPORT ...WHILE xxxxxxxx WENDIF xxxxxx ELSE xxxxxx FIAlso at the point where the CONTROL-SECTION logic is executed, the file reads are done and all formats are loaded into memory so the CTnnE syntax has access to #formatname.
-
The number is the same as any CTnnA or STnn and cannot be the same as any other CTnnA or STnn.
-
The break section of the statement is the same as currently available for a computed total line.
-
The remainder can be any valid Thoroughbred Basic syntax recognized by Report-IV. It will be executed at the time it would have been executed had it been a normal CTnnA.
-
Data names must not start closer to the left than the “L” in the ruler line.
-
If any of the Format data is modified, it should be reassigned. For example:
CT00E ;CALL "ANYPUB"; LET LLFFFFFF = #LLFFFFFF.This reassigns the data just read and may not be the data that will print by the next detail line.
-
Any errors that are caused by the execution are ignored so provision should be made to process any errors.
-
The CTnnE line can only be defined in the CONTROL-SECTION.
EXAMPLES
CT01A WHEN ...CT02A WHEN...CT03E CALL...From the Report-IV Reference, version 8.9.1. Open this page in the PDF