0

How can I sum rows in ABAP using alv report?

sum=gross_weight + net_weight

it creates a new column sum which is the sum of two rows. I have tried using:

wa-fieldname = 'IT_NET_WEIGHT'.
wa-seltext_s = 'Qun'.
wa-ddic_outputlen = '10'.
APPEND wa TO fcat.
wa-fieldname = 'WA_GROSS_WEIGHT'.
wa-seltext_s = 'Qun'.
wa-ddic_outputlen = '10'.
APPEND wa TO fcat.
* Calculate Total for Price
wa-fieldname = 'TOTALS'.
wa-cfieldname = 'WAERK'.
wa-seltext_s = 'Qun'.
wa-do_sum = 'X'. 
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Demotivated
  • 117
  • 3
  • 13

2 Answers2

3

DO_SUM is intended to enable a totals line below the entire table. If you want to have a column that contains the sums, you will have to add this to the data table you're displaying - this is not something the ALV will do for you.

vwegert
  • 18,371
  • 3
  • 37
  • 55
  • I am not trying to sum colums,I want a new colum with the sum of the first two for example gross weight|net_weight|sum 1000 |2000|3000 – Demotivated Jul 14 '17 at 12:59
  • I understood that, but that is not something the ALV components will do for you. – vwegert Jul 15 '17 at 06:36
1

You should expand your internal table with "sum" column. i.e.

LOOP AT itab.
   itab-sum = itab-gross_weight + itab-net_weight.
   MODIFY itab.
ENDLOOP.
BSMP
  • 4,596
  • 8
  • 33
  • 44
Oguz
  • 1,867
  • 1
  • 17
  • 24
  • that works for only for non alv in ALv i try to declare the sum type p,in the structure but it doesnt regognize that – Demotivated Jul 14 '17 at 14:43