Application Development 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: 

sum of an internal table field row wise?

Former Member
0 Kudos

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..

8 REPLIES 8

thangam_perumal
Contributor
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

dea ,

                                       I alredy did the same..but it is populating wrong output

0 Kudos

Wrong value? Do you have same Type and Length for internal table field and sum variable?

Regards,

Naveen

0 Kudos

Dear Ani Har,

                    Please Specify the your internal table structure and your coding..

it would be more helpful to find out the problem...

Former Member
0 Kudos

Hi,

Can u please share the code?

Khairwa
Explorer
0 Kudos

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!

former_member184569
Active Contributor
0 Kudos

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.