Skip to Content
0
Former Member
Apr 28, 2009 at 05:18 AM

how to use Collect and find average

921 Views

Hi Experts,

I want to find the average of certain value on the basis of month , please find the below eaxmaple and

advice me..

For eg:

werks      ,  matnr   ,  lifnr ,  MONTH   ,  TOTAL
unit1      ,   ABCD   ,  TVS  ,   01.2008    ,   100  "need to find avg ie 100+175 / 2
unit1      ,   ABCD   ,  TVS  ,   01.2008    ,   175
unit2      ,   WXYZ   ,  TAG  ,   02.2007    ,   200  "need to find avg ie 200+100+150 / 3
unit2      ,   WXYZ   ,  TAG  ,   02.2007    ,   100
unit2      ,   WXYZ   ,  TAG  ,   02.2007    ,   150

But my O/P should be :

werks , matnr , lifnr , MONTH , TOTAL

unit1 , ABCD , TVS , 01.2008 , 137.50

unit2 , WXYZ , TAG , 02.2007 , 150

===========================================================================

My orginal code 4 ur reference:

SELECT * FROM S068 INTO CORRESPONDING FIELDS OF TABLE IT_S068    
                                                                  WHERE LIFNR IN LIFNR
                                                                 AND MATNR IN MATNR
                                                                  AND WERK  IN WERK
                                                                  AND SPMON IN SPMON
                                                                  AND ART EQ '01'.

LOOP AT IT_S068.

IT_S068-MEANQ = IT_S068-SUMQKZ * 1.     " to convert exponential value to numeric

MODIFY IT_S068 TRANSPORTING MEANQ.
ENDLOOP.

LOOP AT IT_S068.
    MOVE IT_S068-MATNR TO IT_TAB-MATNR.
    MOVE IT_S068-WERK TO IT_TAB-WERK.
    MOVE IT_S068-LIFNR TO IT_TAB-LIFNR.
    MOVE IT_S068-SPMON TO IT_TAB-SPMON.
    MOVE IT_S068-meanq TO IT_TAB-meanq.          "need to find the average
    COLLECT IT_TAB.
  ENDLOOP.

Please advice.

Karthik

Edited by: Karthik R on Apr 28, 2009 10:48 AM

Edited by: Karthik R on Apr 28, 2009 10:49 AM

Edited by: Karthik R on Apr 28, 2009 10:50 AM

Edited by: Karthik R on Apr 28, 2009 10:50 AM