Report driving logicΒΆ

A report is driven by a built-in logic cycle, which automatically reads records from specified files and executes code in specific sections of the program.

A driving file may declared in each !report section. This file is traversed automatically, in ascending key value, by the driving logic, and the main body of statements is executed once for each record in the driving file. By default, the driving file is read from start to end, but initialisation statements may be used to specify the start and/or end record, and also to specify selection and inclusion conditions. Cross reference files may be automatically or manually read as the main driving file is traversed.

When a report commences, the initialisation statements are executed before any records are read from the driving file. The main section is then executed for each record in the driving file. After processing of the driving file terminates, any finalisation sections are executed. During processing of the driving file, other sections are executed automatically when specific conditions occur. These include the start of a new page, enabling automatic page management and the output of heading and footnote statements, or a change in the value of a field, which allows grouping and subtotalling to be easily performed.

The entire execution sequence of a report is as follows:

1

Any initialisation statements (defined in the !init section) are executed.

2

Any title statements (defined in the !title section) are executed.

3

The driving file is then read, in ascending key sequence, from beginning to end or within the limits defined by startrec and endrec commands. Each record is then processed as follows:

4

Control statements are executed, in the order in which they are defined. The control statements are:

!auto

reassign an automatic temporary variable

!exclude

declare an exclusion condition

!select

declare a selection condition

!xfile

read an automatic cross reference file record

These statements may appear in any order and may be mixed. If an !exclude condition evaluates to true (non-zero) and no prior !select condition has evaluated to true, or if there are !select conditions and no !exclude conditions, and no !select condition evaluates to true, processing of the current record terminates immediately.

5

Any !on ending statements are checked. If any require executing, the report backtracks to the state that existed before the current set of records was read, and then executes the appropriate statements.

6

Any !on starting statements are checked and executed as necessary.

7

The main block of statements is executed. These must be terminated with the end command.

8

The average, max, min, total, count function accumulators are updated.

9

Any !on ending statements for the last record are executed, unless the program was terminated by the exit command.

10

Any !final statements are executed, unless the program was terminated by the exit command.

11

The report terminates. If it was terminated by the exit command, the program exits. Otherwise control returns to the line following the run report command.

Heading and footnote sections are executed automatically at the top and bottom of each page.

If the structure of a !report section is not suited to driving file logic, it is possible to bypass the logic altogether by placing the entire report code within the !init and/or !title statements. Note however that at least one main statement must be included. If no main statements are required by the program, a simple method is to use the single command end.

Note also that Sculptor does not automatically throw a new page within !init statements. The newpage command must be used. New pages are thrown automatically in a !title section.


RELATED TOPICS

Declaring the driving file

Reports