Application Development and Automation 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: 
Read only

Select statement

Former Member
0 Likes
633

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
Read only

Former Member
0 Likes
605

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
Read only

Former Member
0 Likes
605

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.

Read only

0 Likes
605

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

Read only

0 Likes
605

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.

Read only

Former Member
0 Likes
605

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.

Read only

Former Member
0 Likes
606

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.