08042004 12:00 PM
Is that possible with a select statement in ABAP or do I need to sum each row by itself then add them together afterwords?
08042004 2:10 PM
Hi all,
try this :
data sum type bsegdmbtr.
exec sql.
SELECT sum(btr1 + btr2) into :sum FROM ztab
where bukrs = 1000
endexec.
Grx Andreas
08042004 12:21 PM
Hi
Not sure what your requirement is.
Assuming your table has field1 and field2 and entries as below.

Field1  Field2 


1  2 
3  4 
5  6 

Do you want to sum up all rows of field1 ( 135 = 9)
with all rows of field2 ( 246 = 12) and put the result (9+12 = 21) into C1 ?
Thanks
Prasad
08042004 12:43 PM
Exactly, we have a table with several rows, Two of these rows are type i.
We would like to sum of the value of both rows in the select statement.
Right now we could only get it to work by
DATA: C1 TYPE i,
C2 TYPE i,
total type i.
SELECT SUM( field1 ) SUM( fiedl2 ) into ( c1 c2 )from tablename.
total = c1 + c2.
08042004 2:10 PM
Hi all,
try this :
data sum type bsegdmbtr.
exec sql.
SELECT sum(btr1 + btr2) into :sum FROM ztab
where bukrs = 1000
endexec.
Grx Andreas
08042004 2:58 PM
08052004 6:29 AM
Hi Craig,
"Namen sind Schall und Rauch "
data sum type p decimals 2.
regards
08272004 4:28 AM
Hi Craig,
this is not possible with a select statement in ABAP. You can use the routine mentioned by you:
DATA: C1 TYPE i,
C2 TYPE i,
total type i.
SELECT SUM( field1 ) SUM( fiedl2 ) into ( c1 c2 )from tablename.
total = c1 + c2.
Of course you can use the exec sql statement proposed by Andreas, but you have to select for the cllient explicitly. There are some disadvantages for native sql, too:
1. platform dependent
2. no syntax check for the native sql part
3. you bypass the SAP database buffer
For more details refer to the online help about EXEC SQL.
Cheers,
Morten