DEFINE section in REPORT
Defines report parameters and local variables.
Syntax
The syntax of the report DEFINE
section is the same as for the
DEFINE
statement, except that you cannot define arrays or array
members for records.
Usage
This section declares a data type for each formal argument in the REPORT
prototype and for any additional local variables that can be referenced only within the
REPORT
program block. The DEFINE
section is required if
you pass arguments to the report or if you reference local variables in the report.
DEFINE
section as to the DEFINE
statement in MAIN
and
FUNCTION
program blocks. There are some differences and exceptions,
however:- Report arguments cannot be of type
ARRAY
. - Report arguments cannot be records that include
ARRAY
members. - Report local variables are not allocated on the stack at every
OUTPUT TO REPORT
call. The scope of the variables in theDEFINE
section is local to the report routine, but the lifetime is the duration of the program, like module or global variables. In other words, report variables persist acrossOUTPUT TO REPORT
calls.
DEFINE
section, if any of
the following conditions is true:- If you specify
FORMAT EVERY ROW
to create a default report, you must pass all the values for each record of the report. - If an
ORDER BY
section is included, you must pass all the values thatORDER BY
references for each input record of the report. - If you use the
AFTER GROUP OF
control block, you must pass at least the arguments that are named in that control block. - If an aggregate that depends on all records of the report appears anywhere except in the
ON LAST ROW
control block, you must pass each of the records of the report through the argument list.
GROUP PERCENT(*)
(anywhere in a report).- Any aggregate without the
GROUP
keyword (anywhere outside theON LAST ROW
control block).
If your report calls an aggregate function, an error might result if any argument of an aggregate function is not also a format argument of the report. You can, however, use global or module variables as arguments of aggregates if the value of the variable does not change while the report is executing.
A report can reference variables of global or module scope that are not declared in the
DEFINE
section. Their values can be printed, but they can cause problems
in aggregates and in BEFORE GROUP OF
and AFTER GROUP OF
clauses. Any references to non-local variables can produce unexpected results. However, if
their values change while a two-pass report is executing.