More about Automatic Repetition
If your report has a series of fields or lines or groups of similar layout or format, it is usually possible to save time in coding by writing one multiple clause instead of several entries with single-operand clauses. Here is a list of cases:
Values in Consecutive Fields
If you have consecutive fields in a line containing literals, you may code multiple COLUMNS and VALUE clauses to avoid writing several entries:
Sources in Consecutive Fields with same Picture
If you have several consecutive fields in a line with the same PICTURE (or if you can expand shorter PICTUREs to match longer ones), you may code multiple COLUMNS and SOURCE clauses in one entry:
Here, as usual, each SOURCE field is a data item defined in the DATA DIVISION of your program (in this particular case, a numeric item). VALUE and SOURCE clauses cannot be combined within the same multiple clause.
Using a single entry like this also makes it easy to total a series of fields by coding just one SUM entry:
If separate entries are used, you would have to total them by writing either: SOURCE TENNIS + GOLF + SWIMMING + CRICKET, or SUM R-TENNIS R-GOLF R-SWIMMING R-CRICKET, placing these data-names on the entries in turn.
Regularly Spaced Columns
If the gap between successive fields is regular, you need not give a COLUMN for each one. Instead, you can combine an OCCURS clause and a STEP phrase:
You can also use OCCURS with a relative COLUMN to provide the gap, in which case the STEP phrase is unnecessary.
Repeating the Same Value
You can combine a single VALUE with an OCCURS clause or a multiple COLUMNS clause, in which case the VALUE is simply repeated:
A single-operand SOURCE field can be similarly repeated, although the occasions for doing so are rarer.
Repeating LINE
The LINE clause also has a multiple form. You may also combine an OCCURS clause with a single-operand LINE clause. (In the latter case, if you use STEP , as you must if the LINE is absolute, it refers to the vertical distance.) If you use a SOURCE, the entire table of SOURCE items must be "read into memory" first. Within the repeating LINE, you may have multiple VALUES and SOURCES clauses. This enables you to improve clarity by stacking your heading values in one place:
(You don’t have to code the literals vertically like this, but it does help the eye.)
Variable Number of Repetitions
If the number of repetitions is variable, you should use the OCCURS clause's keyword TO and DEPENDING ON phrase, whose operand can be any data-name or arithmetic expression. Report writer will then dynamically calculate the actual number of repeats present on each occasion. It is valid for there to be no occurrences, so your minimum can be zero. Any "unused" repeats are treated as ABSENT:
The same method can be used for LINEs. If a body group has a variable number of lines and they are all relative, report writer will take into account only those lines actually present when applying its page-fit test.
Source Items in a Table
If you need to output SOURCE items that are held in a table, report writer will automatically vary an internal data-name which you can then use as a subscript. You can specify a FROM value for the starting point and a BY value for the increment for your subscript, but these are assumed to be 1 if you omit them:
You choose your own data-name for the VARYING clause, but it must not be defined anywhere as a data item in your program. You can reuse the same data-name many times in the REPORT SECTION, except where the VARYING clauses are nested.
You may combine VARYING with a multiple COLUMNS or LINES clause, as well as with an OCCURS clause, and you may output results in more than one dimension. In the next example, the SPORT fields are printed in reverse order:
Repeating Whole Groups Horizontally
The REPEATED clause enables you to place whole groups side-by-side. On each GENERATE, report writer will place the group in an internal buffer, until the last of each set arrives, whereupon the whole set will be printed side-by-side. You should define only the left-hand group.
If a different DETAIL group is GENERATEd - say SOCCER-FIXTURE - or if your program issues a TERMINATE, and there are still left-hand groups in the buffer, these buffered groups are output first, padded out with blank entries on the right where necessary.
Different Levels using the same Control Footing
You will have noticed from some of the preceding examples that a lower CONTROL FOOTING and a higher CONTROL FOOTING often have a very similar layout and you may wish you could code a single report group and use it for any number of control levels. You can do this simply by listing more than one control in the TYPE clause, for example TYPE CF FOR REPORT, YEAR, MONTH or just CF FOR ALL. Any SUM totals are then automatically rolled forward up to each higher level. If any CONTROL FOOTING has a different layout from the others, you can use PRESENT WHEN CONTROL IS YEAR, PRESENT WHEN CONTROL IS MONTH, and so on to vary it.