Using the APIs in a Program

You can use the aggregate range routines whenever you would otherwise use 850-FIND-SUBRNG-<Index> and 860-FIND-NXTRNG-<Index> to access a set of rows for the purpose of applying average, maximum, minimum, or sum functions against a column.

Use the 880-INIT-DBAG-<Index> routine to initialize an aggregation request.

Use the 880-CALC-DBAG-<Index> routine to process an aggregation request against a data set.

The database routines perform an equal condition on all DB Index fields up to the subrange field designated in the WS-DB-SUB-RNG . It performs a "where greater-than and less-than" condition on this index field.

  1. Set the DB- <KeyField> as you would for any database inquiry routine.
  2. Express the ending value for the range key:

    MOVE identifier TO DBRNG-fieldname.

  3. Identify the range key by moving the symbolic constant:

    MOVE <IndexName>-<IndexFieldName> TO WS-DB-SUB-RNG.

  4. Initialize the aggregation request. This initializes the Boolean request fields and the return values:

    PERFORM 880-INIT-DBAG-<Index>.

  5. Set Booleans describing which fields to aggregate and what function to apply.

    SET DBAVG-<Index>-<FieldName> TO TRUE.

    SET DBMAX-<Index>-<FieldName> TO TRUE.

    SET DBMIN-<Index>-<FieldName> TO TRUE.

    SET DBSUM-<Index>-<FieldName> TO TRUE.

  6. Submit the request:

    PERFORM 880-CALC-DBAG-<Index>.

  7. Test for function validity by referencing the COUNT variable:

    IF (DBAG-<Index>-COUNT NOT = ZERO) ...

  8. Un-reference the return values in the fields named DBAG-<Index>-<FieldName> :

    MOVE DBAG-<Index>-<FieldName> TO WS-RESULT.