Aggregate Request Format

In addition to using the D@<FieldName> and D#END#<KeyFieldName> fields as you do with other database inquiry routines, you use procedures to identify the columns in the table to be returned and the aggregate function to be applied. These procedure calls have the following format:

U@DB@AGSET(D<Prefix>@@HANDLE: DA@<Logical>:
'<Function>': '<4GLFieldName>    ': <Occurs>: 
%ADDR(D<Prefix>#AG#<FieldName>):
%ADDR(D<Prefix>#<FcnAbbr>#<FieldName>))

where

  • <Prefix> is the prefix as defined in the Database Definition utility (dbdef) for the database file being used.

  • where <Logical> identifies the database file and index to use to access the database file. The index you refer to in the U@DB@AGSET call must match the index you refer to in the U@DB@AGINIT call.

  • <Function> is the type of operation you want the aggregate procedure to perform. This will be AVG for average, MIN for minimum, MAX for maximum, or SUM for a total sum.

  • <4GLFieldName> is the name of the field as it appears in the Database Definition utility (dbdef).

  • <Occurs> should be set to 1 for non-array fields, and to the number of the occurrence for array fields.

  • <FieldName> is the name of the field as it appears in RPG code.

  • <FcnAbbr> is an abbreviation representing the type of operation the aggregate procedure performs (AV, MI, MA, or SU).

You can request more than one column in a single API call by using the appropriate Boolean field several times with a different field name each time; but you may specify only one function for each call. Thus, in order to derive the average and the sum of any column, you must populate two separate requests and make two separate calls to the API.