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

Help to do Sum

Hi,

i Have internal table with fields like in e.g. below

and i wont to sum the Work days and put it in the last Colman

what is the Best way to do that?

Regards

i have this table without Colman sum_total (empty) .

what i wont is to spread the sum for all appearance of pernr in sum total Colman :

pernr      kostl       work_days        sum_total
 
111             5555             5                   13
111             5555             8                   13
444             6666             10                  15
444             6666             2                   15
444             6666             3                   15
555             5656             3                    6
555             5656             3                    6

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on May 27, 2008 at 02:48 AM

    Hi

    You can try the following way.

    data: begin of itab occurs 0,

    pernr type char3,

    ktosl type char4,

    workd type i,

    sumwr type i,

    end of itab.

    data: it_out like itab occurs 0 with header line.

    itab-pernr = '111'.

    itab-ktosl = '5555'.

    itab-workd = 5.

    append itab.

    itab-pernr = '111'.

    itab-ktosl = '5555'.

    itab-workd = 8.

    append itab.

    itab-pernr = '444'.

    itab-ktosl = '6666'.

    itab-workd = 10.

    append itab.

    itab-pernr = '444'.

    itab-ktosl = '6666'.

    itab-workd = 2.

    append itab.

    itab-pernr = '444'.

    itab-ktosl = '6666'.

    itab-workd = 3.

    append itab.

    itab-pernr = '555'.

    itab-ktosl = '5656'.

    itab-workd = 3.

    append itab.

    itab-pernr = '555'.

    itab-ktosl = '5656'.

    itab-workd = 3.

    append itab.

    loop at itab.

    collect itab into it_out.

    clear it_out.

    endloop.

    clear itab.

    loop at it_out.

    itab-pernr = it_out-pernr.

    itab-ktosl = it_out-ktosl.

    itab-sumwr = it_out-workd.

    modify itab transporting sumwr where pernr eq it_out-pernr

    and ktosl eq it_out-ktosl.

    endloop.

    loop at itab.

    write : itab-pernr, itab-ktosl, itab-workd, itab-sumwr, /.

    endloop.

    Reward points, if it is helpful.

    Regards

    Raja.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 27, 2008 at 03:51 AM

    Hi,

    U can code like----


    SORT ITAB BY PERNR.

    LOOP AT itab.

    AT END OF KOSTL.

    SUM.

    WRITE: / itab-PERNR, itab-KOSTL, itab-TOL.

    ENDAT.

    ENDLOOP.

    Reward if helpful.

    Thanks.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 27, 2008 at 04:32 AM
    sort it by pernr kostl.
    data:sum_val type p.
    loop at itab.
    at new pernr.
    sum.
    sum_val = itab-work_days.
    endat.
    itab-sum_total = sum_val.
    modify itab transporting sum_total where pernr = itab-pernr
    				   and kostl = itab-kostl.
    endloop.
    
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 26, 2008 at 07:21 PM

    hi check this...i hope we can do like this...

    loop at itab.

    at end of pernr.

    sum .

    v_total = sum .

    endat.

    v_total = sum + v_total.

    endloop.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 27, 2008 at 03:07 AM

    Hi Another simple way of doing this is using two internal tables.

    lets say ur output table as you have shown is gi_out.

    declare another table gi_pernr same structure as of gi_out.

    gi_pernr[] = gi_out[]
    sort gi_pernr by pernr.
    delete adjacent duplicates from gi_pernr comparing pernr.
    
    loop at gi_pernr into gw_pernr.
    clear lv_days.
    loop at gi_out into gw_out where pernr = gw_pernr-pernr.
    lv_days = lv_days + gw_out-work_days.
    endloop.
    
    modify gi_out from gw_out transporting sum_total where pernr = gw_pernr-pernr.
    endloop.
    

    .

    This will surely work..

    thnx,

    Ags..

    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.