Skip to content

Control-Section

The CONTROL-SECTION defines the conditions for grouping, sub-totaling, and totaling to be used in the REPORT-SECTION.

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

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.

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 CHANGES
WHEN CUST-CODE(1,2) = "00" OR CUS-STATE CHANGES
WHEN REP-CODE = "009" AND YTD-SALES = "200"
WHEN EOF

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.

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.

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, like simple totals, can be specified in Subtotal and Computed Total lines. Mathematical expressions can be specified as well as Data Names.

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-SECTION
CB01 WHEN INVOICE-NUMBER CHANGES
REPORT-SECTION
CB01 Invoice: XXXXXX
D Invoice Line: XXX

When 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.

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-SECTION
ST01 WHEN REP-CODE CHANGES; ACCTG-COST,
: REVENUE-MTD
REPORT-SECTION
ST01 Total Cost = $###,###.00
ST01 Total Revenue = $###,###.00

This 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.

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-AMT
CT01P WHEN REP-CODE CHANGES

The 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.

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 EOF

The 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.

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 WEND
    IF xxxxxx ELSE xxxxxx FI

    Also 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