Average Sum Maximum Minimum by Select

Average Sum Maximum Minimum by Select

We can calculate the average and sum of any quantity type field directly from select statement. Similarly we can extract the maximum value or minimum value from quantity type field. In the below example the system fetches the data of MENGE field from EKPO table and calculate its average and sum and then put into the packed type variable ‘average’ & ‘sum’ respectively. Similarly it fetches the maximum and minimum values from MENGE and put it packed type variable ‘maximum’ & ‘minimum’. Here the WHERE clause is optional. To avoid the entire field records we have used this clause.

In the database we find this MENGE field with PO number '3000000057'.






















REPORT  zabap_gui.

DATA:
      average TYPE p DECIMALS 2,
      sum     TYPE p DECIMALS 2,
      maximum TYPE p DECIMALS 2,
      minimum TYPE p DECIMALS 2.

* Here the MENGE field of EKPO table has been used
* to calculate the average, sum, maximum & minimum
SELECT AVG( menge )
       SUM( menge )
       MAX( menge )
       MIN( menge )
  FROM ekpo
  INTO (average, sum, maximum, minimum)
  WHERE ebeln = '3000000057'.

WRITE: / 'Average = ', average,
       / 'Sum     = 'sum,
       / 'Maximum = ', maximum,
       / 'Minimum = ', minimum.

Here is the output.


Share this

Related Posts