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: 

Problem in sum a field through select command

Former Member
0 Kudos
249

Dear Sir(s),

I want to sum kbetr (no. of packing) for same knumv(invoice no.) in table konv.

e.g.

invoice no. no. of packing

(knumv) (kbetr)

001 2

001 3

002 4

002 5

result should be -

invoice no no. of packing

001 5

002 9

code-

select knumv kschl sum(distinct kbetr)

from konv

into table it_konv

for all entries in it_vbrk

where kschl = 'ZFQT'

and knumv = it_vbrk-knumv

group by knumv kbetr.

error showing - unkown col. sum(distinct field list.

Please help me immediately.

thanks,

R.Kapoor

1 ACCEPTED SOLUTION

Former Member
0 Kudos
95

u can use at end of statement inside loop statement

loop at it.

write:/ it-field1,it-field2,

at end of kumnv

sum.

endat.

endloop.

reward points if this is useful

9 REPLIES 9

FredericGirod
Active Contributor
0 Kudos
95

select knumv sum( kbetr )

into table it_konv

from ...

group by knumv.

Former Member
0 Kudos
96

u can use at end of statement inside loop statement

loop at it.

write:/ it-field1,it-field2,

at end of kumnv

sum.

endat.

endloop.

reward points if this is useful

varma_narayana
Active Contributor
0 Kudos
95

Hi..

Change ur Select statement as below .

<b>select knumv sum(kbetr)</b>

from konv

into table it_konv

for all entries in it_vbrk

where kschl = 'ZFQT'

and knumv = it_vbrk-knumv

<b>group by knumv .</b>

Here you need not to Retrieve the Field KSCHL since it is anyway given in the WHERE clause.

Let me know incase of any other issue.

<b>Reward if Helpful.</b>

0 Kudos
95

Dear Sir,

I am still facing problem in using sum agregate in select statement.

it showing error again, kindly check at your end and send by mail.

thanks & regards,

Rakesh Kapoor

Former Member
0 Kudos
95

Hi,

try this

<b>select knumv kschl

from konv</b>

into table it_konv

for all entries in it_vbrk

where kschl = 'ZFQT'

and knumv = it_vbrk-knumv

group by knumv kbetr.

sort it_know by knumv.

loop at it_knov.

at end of knumv.

sum.

write:/ it_knov-knumv, it_knov-kbetr.

endat.

endloop.

thanks & regards,

Venkatesh

0 Kudos
95

Dear Sir,

Your solution is very helpful and now i overcome from the problem. hope in future also you will help me in solving problems.

thanks & regards,

Rakesh Kapoor

Former Member
0 Kudos
95

u loop the internal table and then use

ON CHANGE OF in loop and do SUM.

Former Member
0 Kudos
95

data:

it_konv2 like table of it_konv with header line.

select knumv kschl kbetr

from konv

into table it_konv

for all entries in it_vbrk

where kschl = 'ZFQT'

and knumv = it_vbrk-knumv.

loop at it_konv.

it_konv2 = it_konv.

collect it_konv2.

endloop.

**So it_konv2 will have your desired data.

Reward points if useful.Get back in case of query...

Cheers!!!

Former Member
0 Kudos
95

Hi Rakesh,

Use collect statement.

Regards

Arun