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 sum problem.

Former Member
0 Kudos

HI, gurus,

I have a problem with the 'select.. sum ..' clause.

the following is my code:

SELECT sgtxt sum( wrbtr ) FROM bsis
     INTO CORRESPONDING FIELDS OF TABLE it_temp
     WHERE bukrs = '1500'
     AND budat >= '20040131'
     AND budat <= q_date1
     AND hkont = '0012420001'
     AND sgtxt >= 'ORD 300000'
     AND sgtxt <= 'ORD 399999'
     group by sgtxt .

but I can't get the sum value of the field 'wrbtr' ,is the 'CURR' type field couldn't sum in this clause?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Bill,

You have to modify your code as mentioned below.

SELECT sgtxt sum( wrbtr ) as wrbtr

FROM bsis

INTO CORRESPONDING FIELDS OF TABLE it_temp

WHERE bukrs = '1500'

AND budat >= '20040131'

AND budat <= q_date1

AND hkont = '0012420001'

AND sgtxt >= 'ORD 300000'

AND sgtxt <= 'ORD 399999'

group by sgtxt .

thanks & regards

Kishore M

4 REPLIES 4

Former Member
0 Kudos

Hi

The Clauses sum avg in select etc applies to all the records of the query result . it results in a single value.

so better use the below specified query

data : sum_wbetr type wbetr.

SELECT sum( wrbtr ) FROM bsis

INTO sum_wbetr

WHERE bukrs = '1500'

AND budat >= '20040131'

AND budat <= q_date1

AND hkont = '0012420001'

AND sgtxt >= 'ORD 300000'

AND sgtxt <= 'ORD 399999'

group by sgtxt .

u will probably not be using this value sum_wbetr multiple times , so no need to move it into every record of the table as u r doing.

SELECT sgtxt FROM bsis

INTO CORRESPONDING FIELDS OF TABLE it_temp

WHERE bukrs = '1500'

AND budat >= '20040131'

AND budat <= q_date1

AND hkont = '0012420001'

AND sgtxt >= 'ORD 300000'

AND sgtxt <= 'ORD 399999'

group by sgtxt .

Hope this clarifies ur query

Former Member
0 Kudos

Hi Bill,

You have to modify your code as mentioned below.

SELECT sgtxt sum( wrbtr ) as wrbtr

FROM bsis

INTO CORRESPONDING FIELDS OF TABLE it_temp

WHERE bukrs = '1500'

AND budat >= '20040131'

AND budat <= q_date1

AND hkont = '0012420001'

AND sgtxt >= 'ORD 300000'

AND sgtxt <= 'ORD 399999'

group by sgtxt .

thanks & regards

Kishore M

0 Kudos

THX ,Kishore , it works

0 Kudos

Hi Bill,

I want sum of DMBTR from BSIK n BSAS .

As kishore said now i m getting values in it_bsik-dmbtr, but i want to copy this value in var1 which is of type char.

can u plz help me , how to do this???

Thanks & Regards,

Manisha

Edited by: PATIL MANISHA on Jul 29, 2010 9:43 AM