Skip to Content

how to get max , mean and min values of a column from internal table based on material?

Hi Experts,

I gone through sap community forums, though i couldn't find solution. I've requirement to fetch max , min and mean values of a field from internal table based on the group and material.

My internal table having data like

Group Material Original_Value

FGS07 FG320200008003 10

FGS07 FG320200008003 20

FGS07 FG320200008003 30

FGS07 FG320200008007 20

FGS07 FG320200008007 30

FGS07 FG320200008007 40

expecting output is for MAX Value is

FGS07 FG320200008003 30

FGS07 FG320200008007 40

please anybody help me out in this. Thanks in Advance

Regards

satish

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • Posted on Feb 19, 2014 at 10:00 AM

    Hi,

    you have to code it yourself.

    SORT ...

    LOOP ..

    AT NEW ..

    ENDLOOP

    regards

    Fred

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 19, 2014 at 10:08 AM

    Hi Satish,

    There is no direct statement to find the max and min value of an internal table.

    Instead we need to write some logic.

    For Ex: it_mara contains the list of records,.

    sort it_mara BY Group Material DESCENDING.

    Then first record will be maximum value and last records will be the minimum value.

    Inorder to find the mean of original_value for all records then:

    Loop the internal table and add the original_value field to one temp variable. After endloop divide the temp variable by no of records in that internal table. Then you will get mean value of Original_Value field.

    Regards,

    Vineesh.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 19, 2014 at 10:22 AM

    Hi Satish,

    You can try like this too,

    DATA : L_MAX TYPE <field-type>,

    L_MIN TYPE <field-type>,

    L_MEAN TYPE <field-type>.

    SORT ITAB BY <field>.

    LOOP AT ITAB INTO WA.

    IF SY-SUBRC = 1.

    L_MAX = WA-<field>. " Max Value

    ENDIF.

    " Write logic to find mean value and L_MEAN = <value>

    L_MIN = WA-<field>. " at the last record this will hold min value.

    ENDLOOP.

    Regards,

    Vijay

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 19, 2014 at 10:27 AM

    Hi ,

    Check the statement below .

    suppose you r having the data in ti_tab .

    SORT IT_TAB BY VALUE(FIELD) DESCENDING MATNR DESCENDING .

    DELETE ADJACENT DUPLICATES FROM IT_TAB COMPARING MATNR .

    Now IT_TAB has data as below...

    Group
    Material _Value

    FGS07 FG320200008003 30

    FGS07 FG320200008007 40

    Regards

    DJ

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 19, 2014 at 10:43 AM

    Hi ,

    SORT lt_tab BY material value DESCENDING.

    LOOP AT lt_tab INTO wa_tab.

    AT NEW material.

    APPEND wa_tab TO lt_tab1.

    ENDAT.

    ENDLOOP.

    lt_tab1 has your required value.

    BR.
    Giri

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 19, 2014 at 10:14 AM

    loop the records, compare them and create a table of your expected outcomes

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 19, 2014 at 10:43 AM

    Hi guys,

    Thank you all for your initiative and help. now i'm able to get max and min values . trying to get mean value. but i should calculate mean value based on group and material , not based on no.of records in internal table.

    Regards,

    satish

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 19, 2014 at 02:21 PM

    Hi guys,

    Thank you all . My issue has been solved.

    regards

    satish

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.