DEFINE section in REPORT

Defines report parameters and local variables.


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.


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.

For declaring local report variables, the same rules apply to the 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 the DEFINE 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 across OUTPUT TO REPORT calls.
Data types of local variables that are not formal arguments are unrestricted. You must include arguments in the report prototype and declare them in the DEFINE section, if any of the following conditions is true:
  • If you specifyFORMAT 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 that ORDER 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.
Aggregates dependent on all records include:
  • GROUP PERCENT(*) (anywhere in a report).
  • Any aggregate without the GROUP keyword (anywhere outside the ON 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.