Tips on Report Writer - A4000017 - 05 March 2001

This article contains some miscellaneous tips on using totalling in Report Writer. Much of this information originally appeared in various release notes, but does not appear to have been incorporated into the Report Writer manual. This will be done when time permits.

TOTAL Operator

Older versions of the DP4 Report Writer manual state that this returns the total value of the field as it was at the end of the previous line. This is incorrect. The value includes the data for the current line as well. To get the total as defined in the Report Writer manual you would need to define a second, calculate, field whose value was PREV the other field, and total that as well.

The TOTAL operator can only be applied to a field. Until bug fix K4000030 was released REPSETUP did not check for this correctly on Unix, and a non functioning program could be created.

When using totals you should bear in mind that several levels of total may be kept, depending on whether the program contains multiple break fields or not. Generally speaking totalled fields should come after the fields the total is broken on. It appears that totals to the left of a break are not always maintained correctly, but this has not been investigated in detail yet.

Grand Totals

Since version 4.420 Report Writer has only printed totals on the grand totals line, and not other fields set to be listed on break lines. This is probably not the behaviour one would wish for. However in the interests maintaining compatibility the current behaviour will not be changed - i.e. only totalled variables will be printed on the grand total page. However it is quite easy to print out a grand total line with with other fields. All that is necessary is to put a break on a field which never changes (such as a run time input field or a dummy field) prior to all the other break fields. A break line will only be printed for this field at the end of the report and will contain the correct fields.

If you do this you will probably wish to suppress the grand totals.

Spurious listing of constant fields on break lines

If you have multiple breaks and a constant field should be listed on one break level but not the others you should try the effect of making the field a break field. As the field never changes no extra breaks will be produced and the field will still be listed on the first 'real' break level to the left. Alternatively you can try making the break to which the local (calculated) fields belong a 'local' break.

Rules used by REPPRINT to determine what to print

The following information was originally included in the 4.420 release notes, but is still correct as far as the author knows.

This section is provided to enable users of Report Writer to know what their Report Writer program should look like. It is provided for two related reasons:

  1. At the top of each page various headings are printed under user control containing information about what report is being printed and when, followed by the users heading, followed by headings for the fields of the report. If the report is folded then all the headings for all the field are printed unless fold headers are selected in which case just the headers for the next fold to be printed are printed. For exports any headings are normally omitted, and if included they are printed only on page 1 of the report.

  2. For each record processed a detail line will be printed unless it is a subtotal only report. For the first line of the report all the fields which are listed are printed. On subsequent lines only fields that have changed or which are repeated are printed until a break occurs. Following a break all the fields to the right of the break will be printed even if they have not changed. If the first line of a new page is a detail line all the fields will be printed then too, but if the first line of a page is a break line then the next detail line will be printed normally. If a report is a subtotal only report which has some 'list before break' fields then a detail line will produced before every break.

  3. If the value of a field which is a break field changes than a break line is printed. If there are multiple break fields than a break on any particular level necessarily implies that there is a break on all the subsequent break fields. If several breaks occur at once then as many as possible of them are superimposed. The algorithm used to superimpose is slightly complicated to explain but the basic idea is simple: if the number of records processed since the last break at a particular level is the same as the number of records at a lower break level (that is a break field that is nearer the top of the field list) then the fields for the two break levels are grouped together. In each such case the lowest and highest break levels that have matching record counts are processed together.

  4. Fields are listed on a break line if they are at or to the right of the lowest break in the group being processed and before the break field after the last break field in the group. Fields to the right of this are printed if they are not break fields and are totalled or calculated. Fields to the left are printed if the break line is being printed at the top of the page, or if the last break line was at a lower level and no detail lines hace been printed since (which can only happen in subtotal only reports), but only if they are set to be listed on break alines and also on detail lines.

    Example. Consider the following data. The first three fields are all break fields. All the fields are listed, the break fields are not repeated and all the fields are listed on total line. The numeric field is totalled.

       A B C 1.0
       A B C 1.3
       A B D 1.0
       B A D 2.0
       B A D 1.0
    

    The following output should be produced. Subtotal lines are asterisked.

       A B C 1.0
             1.3
    
           C 2.3 *
    
           D 1.0
                   (Not printed if you suppress one item subtotals)
           D 1.0 * (Not printed if you suppress one item subtotals)
    
       A B   3.3 *
    
       B A D 2.0
             1.0
    
       B A D 3.0
    
             6.3  (This is the grand total and would be printed on the
                   grand totals page only)
    
  5. Treatment of multi occurrence fields.

    If a multi occurrence field is listed but not repeated REPPRINT will superimpose lines like this:

       Name         Customer Address        Unpaid Invoices   Amount
    
       Major        10 Downing St           1000              £ 10
                    London                  1001              £100 SW1
       Major                                                  £110
    
  6. Formulas

    Formulas. When a calculated field is printed on a subtotal line then if it is calculated using any totalled fields then the field is calculated using the total that appears on that line.

  7. Exports

    Exports are not paginated and no spacing lines are printed before or after subtotals. The delimiter is not printed on the last field.

  8. Field Layout

    The width occupied by a field is whichever is the wider of the heading and the width required to display the selected number of occurrences.

    For numeric fields that are right justified (including fields with leading zeros or asterisks) the heading and the field itself are right justified within this width.

    For fields other than numeric fields, and for numeric fields, if left justified output or default format are selected, then both the heading and the data begin immediately following the spacing from the previous field.

Using maps

REPPRINT does all its output using maps created by REPSETUP. It is therefore theoretically possible to tailor the output by editing the maps but most of the maps are reposted every time the report is edited. However the following maps are not altered once they have been posted by REPSETUP.

Map NrDescription
3 Printed before grand total
4 Printed after grand total
6 Printed at bottom of each page except the last - normally blank
7 Printed at top of each page unless -nocopy specified
10 End of report

The other maps are as follows: