12-18-2013 6:31 AM
how to find total of a internal dynamic table's field row wise..i think 'COLLECT' statement will not work in that situation....how can we find total in that...?
loop,
sum = quantity + sum .
celear sum.
end loop.
sum1 = sum + sum1.
it is also not calculating exact value...
plz solve......
thanks in advance..
12-18-2013 6:38 AM
Hi Ani Har,
Please Refer the Below Modified Code.
Consider internal is ITAB with header Line.
data: Sum type P length 8 decimal 2.
Loop at ITAB .
sum = sum + itab-quantity .
clear: itab-quantity.
endloop.
Write: Sum.
After completing the Loop the resulting total available in varialble SUM.
collect statement also works if Quantity field is Packed decimal or Integer.
Regards,
Thangam.P
12-18-2013 6:40 AM
HI Ani,
where will you collect the sums for each row ?
do you have any specific field in your internal table to collect them ?
sharing your table structure will be more helpful for us to analyse this.
thanks,
bhaskar
12-18-2013 6:48 AM
dea Thangam Perumal,
I alredy did the same..but it is populating wrong output
12-18-2013 7:27 AM
Wrong value? Do you have same Type and Length for internal table field and sum variable?
Regards,
Naveen
12-18-2013 8:10 AM
Dear Ani Har,
Please Specify the your internal table structure and your coding..
it would be more helpful to find out the problem...
12-18-2013 6:52 AM
12-18-2013 7:22 AM
Loop at ITAB
* use sum_row for populating another column in ITAB or just use WRITE statement to output row wise total
sum_row = sum_row + ITAB-quantity + ...
* use sum_tot to collect sum_row
sum_tot = sum_tot + sum_row.
Clear: sum_row.
Endloop.
now,sum_row will contain sum row wise.
sum_tot will contain sum of all rows.
cheers!
12-18-2013 7:29 AM
Hi Ani,
If its a dynamic table use this logic given in the comments section for calculating the row wise total. Do it at the time you are populating the contents.
If its a normal table use field symbols. If there are n fields to be added, eg quant1, quantity2 quantit3, .. quantn etc. and qaunt1 is the third field.
loop at itab into wa_itab.
do n times.
pos = 3.
assign component pos of structure wa_itab to <fs1>.
if <fs1> is assigned.
lv_total = <fs1> + total.
endif.
pos = pos + 1.
enddo.
assign component 'TOTAL' of structure wa_itab to <fs1>.
if <fs1> is assigned.
<fs1> = lv_total.
endif.
endloop.