Previous Topic: Avoiding Unwanted Buffer DumpsNext Topic: JCL Considerations


Creating Subtotal Work Fields for Presorted Input Files

If your input file is presorted, it is more efficient to use type 7 logic to accumulate totals in a work field rather than allow CA Culprit to automatically total the fields each time a control break occurs on a SORT parameter.

Two different techniques for reporting total amounts by city are shown below:

  1. This example uses type 7 logic to accumulate the total amount in a work field until the value of CONTROL-FLD changes. This method is extremely efficient, since NOSORT is required and only 7 extract records will be written to the extract file.
    IN 200
    REC CONTROL-FLD   1  4
    REC INPUT-FLD     5  9  2
    0151*002  SAVE-FLD   HH 'CONTROL'
    0151*004  BUCKET     HH 'AMOUNT'
    010 SAVE-FLD '    '
    010 BUCKET 0
    017     EOF = TAKE                    $Print last work field
    017     CONTROL-FLD NE SAVE-FLD  100  $Control change?
    017     INPUT-FLD + BUCKET  BUCKET    $Accumulate
    017     DROP                          $Get next record
    017100  RELS                          $Previous control-fld
    017     MOVE CONTROL-FLD TO SAVE-FLD  $Save current information
    017     MOVE INPUT-FLD TO BUCKET      $Save first amount
    017     DROP                          $Get next
    
  2. This example takes full advantage of CA Culprit's automatic subtotaling capabilities and does not require a presorted input file. However, it is less efficient because every record on the input file will be written to the extract file, which must then be sorted.
    IN 200
    REC CONTROL-FLD   1  4
    REC INPUT-FLD     5  9  2
    0261*002  CONTROL-FLD  HH 'CONTROL'
    0261*004  INPUT-FLD    HH 'AMOUNT'
    02SORT  CONTROL-FLD 0
    02OUT T
    027 TAKE
    

Output

     CONTROL              AMOUNT       BOSTON              136,409       CLEV                 17,500       DENV                140,000       NYC                  17,170       PHIL                267,000       SF                   20,090       TAMP                  2,000                           600,169

When you are coding a CA Culprit report, keep in mind these efficiency guidelines:

  1. Always seek to limit I/O activity by reducing the size of the extract file. DROP records in type 7 logic whenever possible.
  2. Avoid coding unnecessary SORT parameters. If your input file is presorted and you want control breaks, use the NOSORT option.
  3. CPU activity is less expensive than I/O activity.