Scripts are always evaluated in the Report Generator phase, not in the Query Processor phase. When a report variable is used in more than one script, the order in which the scripts are executed is important.
There are up to three phases in the execution of a report. Within each phase, scripts are evaluated in ascending order of name unless there is a dependency between them that changes this.
The first process, the pre-process occurs when the Report Generator phase first starts, before any data from the Query Processor phase has been read. The pre-process covers scripts which do not access any data items. These scripts are evaluated once at the start.
The second process, called the reading phase occurs when the data for the report is read from the Query Processor phase. Scripts that are used selection, group, or sort criteria and those themselves summarized are evaluated at the reading phase.
The third process, the printing phase occurs when the data is printed. If both the reading phase and printing phase are present, the printing phase is a second reading of the data from the query engine, otherwise the reading phase and printing phase are combined. For example, with scripts A and B evaluated at pre-process time, C and D in the reading phase and E and F at print time, and three sets of data items (effectively three detail lines) present, data1 through data3, the overall order of script evaluation is:
A
B
C (data1)
D (data1)
C (data2)
D (data2)
C (data3)
D (data3)
E (data1)
F (data1)
E (data2)
F (data2)
E (data3)
F (data3)