Previous Topic: UPDATE StatementNext Topic: Specifying Functions at Control Breaks


WHEN/DO Statements

Purpose

The WHEN/DO statement specifies when a mathematical function or page break is to be performed and what column will be the object of the mathematical function.

Since only one PRINT statement can be present in the query, the PRINT statement must be completed before the WHEN/DO statement is given. There can be multiple WHEN statements in the query, and there may be multiple DO statements for any WHEN statement.

You can perform mathematical functions when a control break occurs, or at the end of the report. Mathematical functions which you can specify in the DO statement are AVG, CNT, MAX, MIN, and SUM. See Designating Control Breaks for more information.

Syntax Diagram

The following diagram shows the syntax of a WHEN/DO statement.

►►─ WHEN ─ table-name ─┬────────────┬─ named-control-break ───────────────────►
                       └─ (status) ─┘

 ►─┬────────────┬─ DO ────────────────────────────────────────────────────────►
   ├─ BREAKS ───┤
   └─ FINISHED ─┘

 ►─┬─ PAGE-BREAK ─┤ more-choices ├ ─────────────────────┬─────────────────────►
   └─┬───────────────────┬─ function ─┤ more-choices ├ ─┘
     └─ 'report-legend' ─┘

 ►─┬──────────────────────────┬───────────────────────────────────────────────►◄
   └─ PICture 'edit-pattern' ─┘

Expansion of more-choices

├──┬─ 'table-name ─┬────────────┬─ 'column-name ─┬─────────────────────────────┤
   │               └─ (status) ─┘                │
   └─ result-name ───────────────────────────────┘

Repeat WHEN statement once for each function or page break wanted. Multiple DO statements may be used with one WHEN statement.

To simplify discussion, we present the options of the WHEN/DO statement in the following sections.

Mathematical functions at control breaks

Section Specifying Functions at Control Breaks

Mathematical functions at the end of report

Section End of Report

Specifying page breaks in the output

Section Page Break

Multiple DO clauses

Section Specifying Multiple DO Statements