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: 

Select statement

Former Member
0 Kudos
99

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos
71

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.

5 REPLIES 5

Former Member
0 Kudos
71

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.

0 Kudos
71

Okey, thanks! So it's not posible to do this without using an internal table?

0 Kudos
71

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.

Former Member
0 Kudos
71

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.

Former Member
0 Kudos
72

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.