‎2007 May 16 10:17 AM
Can i write a sql that will sum up all quantity with debit/credit indicator. For example
In table of mseg, i need to sum up the MENGE which related to specific material number, but i have to care about SHKZG, i can't use to the following SQL
select sum( MENGE ) FROM mseg group by matnr.
Can i write a simple sql which will sum up MENGE with credit/debit indicator. Thanks
‎2007 May 16 10:20 AM
Hi ,
Don't write select query . Use <b>SUM</b> command
select menge from mseg into itab.
SUM.
Regards,
Hemant
‎2007 May 16 10:22 AM
hI,
No, you cannot write sql like this at max u can write:
select sum(menge) from mseg group by matnr shkzg. "This will reduce resultset records.
or simply do :
loop at itab.
if itab-shkzg = <+>.
toatal_menge = total_menge + itab-menge.
else.
toatal_menge = total_menge - itab-menge.
endif.Jogdand M B
‎2007 May 16 10:28 AM
There is no SQL to help you sum one field according to the values of another field.
You need to select the data into an internal table and sum.
SELECT menge shkzg INTO itab.
DATA: sum type menge.
LOOP at itab.
CASE itab-shkzg.
WHEN 'H'.
sum = sum + itab-menge.
WHEN 'S'.
sum = sum - itab-menge.
ENDCASE.
ENDLOOP.
The + and - will vary according to situation.
Hope this helps