Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

finding sum as per date.

Former Member
0 Likes
1,379

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.

3 REPLIES 3
Read only

Former Member
0 Likes
788

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.

Read only

Former Member
0 Likes
788

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

Read only

Former Member
0 Likes
788

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