Accessing Database Records
- Set the D@ key fields as you would for any database inquiry routine.
- Express the ending value for the range key:
EVAL D#END#<FieldName> = <identifier> - Identify the range key by setting E@DBSUBRNG to a number that represents the position of the key field in the index.
EVAL E@DBSUBRNG = <IndexPosition> - Initialize the aggregation request.
CALLP U@DB@AGINIT(D<Prefix>@@HANDLE:%ADDR(DA@<Logical>)) - Set the fields to aggregate and what function to apply.
CALLP U@DB@AGSET(DGAM@@HANDLE: DA@DBGLGAM2:'SUM': 'CR-AMOUNT ': I2:%ADDR(DGAM#AG#CRAMNT(I2)):%ADDR(DGAM#SU#CRAMNT(I2))) - Submit the request:
CALLP DS@DB<Logical>(E@DBAGGREGATE) - Test for function validity by checking the D<Prefix>@NOTFOUND variable.
IF D<Prefix>@NOTFOUND = FALSE - Un-reference the return values in the fields named D<Prefix>#AG#<FieldName>:
Z-ADD D<Prefix>#AG#<FieldName> = <StorageField>