banner ads

Group By

Group By clause categorizes and summarizes the lines of database table based on a single field. That single field is mentioned in the group by clause. We can use multiple fields in the group by clause also. Here the database table records will be summarized according to those fields.

The fields mentioned in the group by clause cannot be specified for the aggregate function. We have to use other fields which are not specified in group by clause to calculate the aggregate function. Now we have the a PO with the following quantity.

REPORT  zabap_gui.

      ebeln  TYPE ekpo-ebeln,
      po_max TYPE p DECIMALS 2,
      po_min TYPE p DECIMALS 2,
      tq_max TYPE p DECIMALS 2,
      tq_min TYPE p DECIMALS 2.

WRITE:/    'PO No',
        15 'Max PO Quantity',
        35 'Min PO Quantity',
        55 'Max Target',
        70 'Min Target'.

SELECT ebeln
       MAX( menge ) MIN( menge )
       MAX( ktmng ) MIN( ktmng )
  FROM ekpo
  INTO (ebeln,
        po_max, po_min,
        tq_max, tq_min)
  GROUP BY ebeln.

  WRITE:/   ebeln,
         15 po_max,
         35 po_min,
         55 tq_max,
         70 tq_min.


Here is the output:

No comments