Skip to Content
author's profile photo Former Member
Former Member

Standard deviation in abap

Dear Freinds,

I want to calculate standard deviation of my internal table columns in abap code , please help me how to calculate it .

Thanks,

Naveen

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on May 02, 2009 at 11:50 AM

    hi,

    try this code for calculating it:-

    
    REPORT abc.
    
    DATA : BEGIN OF itab OCCURS 0,
    num TYPE i,
    END OF itab.
    data : std type p decimals 2.
    
    *-------------------------------------------------
    
    itab-num = 8. APPEND itab.
    itab-num = 25. APPEND itab.
    itab-num = 7. APPEND itab.
    itab-num = 5. APPEND itab.
    
    itab-num = 8. APPEND itab.
    itab-num = 3. APPEND itab.
    itab-num = 10. APPEND itab.
    itab-num = 12. APPEND itab.
    itab-num = 9. APPEND itab.
    
    
    
    
    PERFORM stdev changing std..
    
    
    write :/ std.
    
    
    *-------------------------------------------------
    *-------------------------------------------------
    *-------------------------------------------------
    
    FORM stdev CHANGING std.
    
    DATA : mn TYPE p DECIMALS 2.
    DATA : sm TYPE i.
    DATA : sm2 TYPE i.
    DATA : dev TYPE p DECIMALS 2.
    
    DATA : cnt TYPE i.
    
    LOOP AT itab.
    sm = sm + itab-num.
    cnt = cnt + 1.
    sm2 = sm2 + ( itab-num * itab-num ).
    ENDLOOP.
    
    mn = sm / cnt.
    
    dev = ( sm2 - ( ( ( sm * sm ) / cnt ) ) ) / ( cnt - 1 ) .
    dev = SQRT( dev ).
    
    std = dev.
    
    ENDFORM. "stdev
    

    Edited by: ricx .s on May 2, 2009 1:50 PM

    Edited by: ricx .s on May 2, 2009 1:51 PM

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 19, 2015 at 11:41 AM

    REPORT YP_STD_DEVIATION.

    DATA : BEGIN OF ITAB OCCURS 0,

    NUM TYPE I,

    END OF ITAB.

    DATA : STD TYPE P DECIMALS 2.

    *-------------------------------------------------

    ITAB-NUM = 9. APPEND ITAB.

    ITAB-NUM = 2. APPEND ITAB.

    ITAB-NUM = 5. APPEND ITAB.

    ITAB-NUM = 4. APPEND ITAB.

    ITAB-NUM = 12. APPEND ITAB.

    ITAB-NUM = 7. APPEND ITAB.

    ITAB-NUM = 8. APPEND ITAB.

    ITAB-NUM = 11. APPEND ITAB.

    PERFORM STDEV CHANGING STD..

    WRITE :/ STD.

    *-------------------------------------------------

    *-------------------------------------------------

    *-------------------------------------------------

    FORM STDEV CHANGING STD.

    DATA : MEAN TYPE P DECIMALS 2.

    DATA : CSUM TYPE I. "Count Sum

    DATA : SM1 TYPE I.

    DATA : NSSUM TYPE I."Net Sqre Sum

    DATA : DEV TYPE P DECIMALS 2.

    DATA : CNT TYPE I.

    **Mean = Sum of X values / N(Number of values)

    LOOP AT ITAB.

    CSUM = CSUM + ITAB-NUM.

    CNT = CNT + 1.

    "NSS = NSS + ( ITAB-NUM * ITAB-NUM ).

    ENDLOOP.

    MEAN = CSUM / CNT.

    ** "Find the variance,

    "square all, Add all the Squared numbers

    LOOP AT ITAB.

    SM1 = ITAB-NUM - MEAN.

    NSSUM = NSSUM + ( SM1 * SM1 ).

    ENDLOOP.

    BREAK-POINT.

    **

    DEV = 1 / CNT * NSSUM.

    DEV = SQRT( DEV ).

    STD = DEV.

    ENDFORM. "stdev

    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.