Skip to Content
0
Former Member
Jul 17, 2008 at 11:38 AM

Summing several fields with SELECT SUM

14667 Views

Hi abappers.

I'm going BONKERS on this silly problem which would take all of about 2 secs to do in something like MySQL.

The wretched examples with that silly airline application in the SAP help is worse than useless. In all my years of working with SAP I don't think I've EVER found a SINGLE instance of finding a solution to any prioblem I've ever had from the Airline application.

I've got a table which is sorted on Plant (WERKS) and Material (NATNR) and some quantity fields fror financial period.

There's sevral records per plant/material.

I want to sum up 2 quantity fields per plant / material.

This code gives me an error - comma without preceding colon (after SELECT ?).


data: lv_werks   type msku-werks,
      lv_matnr   type mara-matnr,
      lv_sum     type msku-kulab.


loop at t_horizontal into wa_ty_horizontal.
    select werks matnr sum( kulab,kuins )
    into  (lv_werks, lv_matnr, lv_sum )
      from msku
      where matnr eq wa_ty_horizontal-matnr
      and werks eq wa_ty_horizontal-werks
      group by werks matnr.
  endselect.
  * process total value  some other non relevant code here
endloop.

This works but only sums up ONE field -- I want the aggregate of BOTH fields however.


loop at t_horizontal into wa_ty_horizontal.
    select werks matnr sum( kulab  )
    into  (lv_werks, lv_matnr, lv_sum )
      from msku
      where matnr eq wa_ty_horizontal-matnr
      and werks eq wa_ty_horizontal-werks
      group by werks matnr.
  endselect.
  * process total value  some other non relevant code here
endloop.

.

the object is to avoid having to sum the two fields manually

Thanks

jimbo.