Using the Aggregate Range APIs

This section lists the steps and shows the source code you must use to use these aggregate range routines.

Programming Example

The following example uses the aggregate range routines to specify the SUM function.

***Using aggregate range routines to specify 
***the SUM function

MOVE WS-COMPANY               TO DB-COMPANY.
MOVE WS-ACCOUNT               TO DB-ACCOUNT.
MOVE WS-FROM-SUB-ACCT         TO DB-SUB-ACCOUNT.
MOVE WS-THRU-SUB-ACCT         TO DBRNG-SUB-ACCOUNT.
MOVE GLMSET1-SUB-ACCOUNT      TO WS-DB-SUB-RNG.
PERFORM 880-INIT-DBAG-GLMSET1.
SET  DBSUM-GLMSET1-AMOUNT (WS-PERIOD)      TO TRUE.
SET  DBSUM-GLMSET1-AMOUNT (WS-PERIOD+1)    TO TRUE.
SET  DBSUM-GLMSET1-AMOUNT (WS-PERIOD-1)    TO TRUE.
PERFORM 880-FIND-DBAG-GLMSET1.
IF (GLMASTER-FOUND)
  MOVE DBAG-GLMSET1-AMOUNT (WS-PERIOD)
                           TO WS-CURR-PERIOD-TOTAL
  MOVE DBAG-GLMSET1-AMOUNT (WS-PERIOD + 1) 
                           TO WS-NEXT-PERIOD-TOTAL
  MOVE DBAG-GLMSET1-AMOUNT (WS-PERIOD - 1) 
                           TO WS-PREV-PERIOD-TOTAL.

Now, compare the code for the aggregate range routines to the code you would have to write to get the same functionality by using the 850-FIND-SUBRNG-<Index> and 860-FIND-NXTRNG-<Index> routines, shown in the following example.

*** Using SUBRNG routines to specify the SUM function

MOVE WS-COMPANY                    TO DB-COMPANY.
MOVE WS-ACCOUNT                    TO DB-ACCOUNT.
MOVE WS-FROM-SUB-ACCT              TO DB-SUB-ACCOUNT.
MOVE WS-THRU-SUB-ACCT              TO DBRNG-SUB-ACCOUNT.
MOVE GLMSET1-SUB-ACCOUNT           TO WS-DB-SUB-RNG.
PERFORM 850-FIND-SUBRNG-GLMSET1.
PERFORM UNTIL (GLMASTER-NOTFOUND)
  ADD GLM-AMOUNT (WS-PERIOD)       TO WS-CURR-PERIOD-TOTAL
  ADD GLM-AMOUNT (WS-PERIOD + 1)   TO WS-NEXT-PERIOD-TOTAL
  ADD GLM-AMOUNT (WS-PERIOD - 1)   TO WS-PREV-PERIOD-TOTAL
  PERFORM 860-FIND-NXTRNG-GLMSET1
END-PERFORM.