Understanding ReportWriter optimization
ReportWriter optimizes its performance by doing the minimum amount of I/O to your data files and by sorting only when necessary.
By default, reports are processed in primary key order on the primary file. To process the primary file in a different order, sort on that field.
If the sort key specifications (all sort fields combined) match the initial segment(s) of an access key on the primary file, the access key is used instead of sorting.
Additionally, if you specify selection criteria that use the access key that’s being used to read the file, the following optimizations are performed:
- If an EQ, GE, or GT selection is done on initial segment(s) of the key, these criteria are not immediately preceded by an OR and not followed by any OR, and the values being tested against are literals, an initial key value is constructed so that a READ to the first desired record can be performed.
- If an EQ, LE, or LT selection is done on initial segment(s) of the key, these criteria are not immediately preceded by an OR and not followed by any OR, and the values being tested against are literals, no further records are processed when that test fails.
If the sort key specifications do not match any of the access keys, sorting takes place. However, because selections are performed before sorting, if you specify selection criteria that use the primary access key, the optimizations described above are performed.
When using a relative file as the primary file, the access key being used to read the file is the record number. If you don’t want to process every record in the primary file, you can optimize the performance by defining selection criteria that test the record number. For example, if the record number is your customer ID, and you only want to process records from ID 20 through ID 50, define a calculation field that is assigned the %RECNUM intrinsic function. Then define selection criteria that compare the calculation field (the current record number) against the values 20 and 50.