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

finding sum as per date.

Hi ,

I have an internal table in the following format.

date amount

01.01.2008 $50

10.01.2008 $50

02.12.2007 $100

14.12.2007 $100

17.12.2007 $100

Now the month and year for the first 2 values are same and for the next 3 are the same..

I want to sum the amount corresponding to the same month and year..

Jan 08 = 100

Dec07 = 300.

How to do this summation in the internal table and move to another internal table.

Kindly help.

Thanks.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Feb 01, 2008 at 07:07 AM

    if possible try convert the date field into yyyymmdd format. and sort the itab based on date field

    try with this i am not sure.

    loop itab.

    at new date+0(6).

    clear sum.

    endat.

    sum = sum+amt.

    at end date+0(6).

    display sum.

    endat.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 01, 2008 at 07:08 AM

    Hi,

    Do like this

    data: lv_lines  type i,
            cnt type i.
    
    Describe table itab lines lv_lines.
    Loop at itab into wa.
     cnt = cnt + 1.
     if wa-date+3(2) = wa1-date+3(2).
      wa1-amount = wa-amount + wa1-amount.
      delete itab from wa.
      append wa1 to itab.
     endif.
     if cnt = lv_lines.
      exit.
     endif.
     wa1 = wa. 
    endloop.
    

    Regards,

    Satish

    Edited by: Satish Panakala on Feb 1, 2008 7:10 AM

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 01, 2008 at 07:13 AM

    say the stucture of internal table is

    data: begin of itab,

    date

    amount

    end if itab.

    *Totals table-

    itot.(say)

    then process as

    loop at itab.

    move corressponding itab to itot.

    append itot.

    On change of itab-date(6).

    clear itot.

    loop at itab.

    itot-amount = itot-amount + itab-amount.

    endloop.

    append itot.

    endon.

    clear itot.

    endloop.

    Hope the above logic helps

    Regards

    Vijai

    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.