2006 Jun 15 8:25 AM
Hi everyone!
How do I modify this statment to summarize ZNEDSLAG-ZZOMSTOTAL on distinct kunnr (customernumber)?
SELECT SUM( zzomstotal ) INTO zvarenytt_i-sentrallager FROM znedslag
WHERE kunnr IN s_kunnr.
TABLE ZNEDSLAG:
kunnr zzvar zzomstotal
30005 A 10
30005 B 10
30006 C 9
30007 D 2
RESULT I WANT:
zzomstotal
21
Best regards,
Jørgen
2006 Jun 15 8:43 AM
It is advised not to use Aggregate functions.
select KUNNR ZZOMSTOTAL
into table itab
where kunnr in s_kunnr.
if sy-subrc eq 0.
sort s_kunnr by kunnr zzomstotal.
loop at itab.
at end of kunnr.
SUM.
write : itab-zzsomstotal.
*C-- You will get the sum of value for distinct kunnr.1
endat.
endloop.
endif.
2006 Jun 15 8:29 AM
data: begin of itab occurs 0,
kunnr type kunnr,
zzomstotal like znedslag-zzomstotal,
end of itab.
SELECT kunnr SUM( zzomstotal ) INTO itabFROM znedslag group by kunnr
WHERE kunnr IN s_kunnr.
append itab.
endselect.
2006 Jun 15 8:48 AM
Okey, thanks! So it's not posible to do this without using an internal table?
2006 Jun 15 9:02 AM
ya u have to need internal table or variable to store the sum value . after store value into variable u update z table with condition kunnr.
2006 Jun 15 8:42 AM
DATA : Sum TYPE i.
sum = 0 .
Read table ZNEDSLAG into zvarenytt_i with key Kunnr .
if sy-subrc = 0.
sum = sum + zvarenytt_i-zzomstotal.
endif.
Write sum.
Rgds,
Jothi.
Mark useful answers.
2006 Jun 15 8:43 AM
It is advised not to use Aggregate functions.
select KUNNR ZZOMSTOTAL
into table itab
where kunnr in s_kunnr.
if sy-subrc eq 0.
sort s_kunnr by kunnr zzomstotal.
loop at itab.
at end of kunnr.
SUM.
write : itab-zzsomstotal.
*C-- You will get the sum of value for distinct kunnr.1
endat.
endloop.
endif.