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

How do sum(field1+field2) in opensql?

Former Member
0 Likes
1,077

I want sum more than one field in opensql,But the follow sentences are wrong:

SELECT SINGLE sum( hsl12 ) + sum( hsl13 ) FROM faglflext INTO ....

SELECT SINGLE sum( hsl12 + hsl13 ) FROM faglflext INTO ....

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
949

i think you cant do it in open sql....

do like that.

data : begin of itab occurs 0,

f1 type i,

f2 type i,

total type i,

end of itab.

select f1 f2 into corresponding fields of table itab from dbtab where.....

loop at itab.

itab-total = itab-f1 + itab-f2.

modify itab.<or you can write the data also>

endloop.

regards

shiba dutta

5 REPLIES 5
Read only

Former Member
0 Likes
950

i think you cant do it in open sql....

do like that.

data : begin of itab occurs 0,

f1 type i,

f2 type i,

total type i,

end of itab.

select f1 f2 into corresponding fields of table itab from dbtab where.....

loop at itab.

itab-total = itab-f1 + itab-f2.

modify itab.<or you can write the data also>

endloop.

regards

shiba dutta

Read only

Former Member
0 Likes
949

Hi..

select those two fields into a field string andd then add them...

if there are more fields to be added..then use DO...VARYING...FROM...NEXT...TO add those after getting them into field string.

Read only

Former Member
0 Likes
949

Hi,

You cannot do that operation in SELECT statement.

You have to save your data in Internal table, and than calculate it in loop processing.

Regards,

Read only

Former Member
0 Likes
949

hi

good

try this

TABLES SBOOK.

DATA: COUNT TYPE I, SUM TYPE P DECIMALS 2, AVG TYPE F.

DATA: CONNID LIKE SBOOK-CONNID.

SELECT CONNID COUNT( * ) SUM( LUGGWEIGHT ) AVG( LUGGWEIGHT )

INTO (CONNID, COUNT, SUM, AVG)

FROM SBOOK

WHERE

CARRID = 'LH ' AND

FLDATE = '19950228'

GROUP BY CONNID.

WRITE: / CONNID, COUNT, SUM, AVG.

ENDSELECT.

go through this link

http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/select_c.htm

thanks

mrutyun^

Read only

Former Member
0 Likes
949

DATA: sflight_tab TYPE SORTED TABLE OF sflight

WITH UNIQUE KEY carrid connid fldate,

sflight_wa LIKE LINE OF sflight_tab.

SELECT *

FROM sflight

INTO TABLE sflight_tab.

LOOP AT sflight_tab INTO sflight_wa.

AT NEW connid.

WRITE: / sflight_wa-carrid,

sflight_wa-connid.

ULINE.

ENDAT.

WRITE: / sflight_wa-fldate,

sflight_wa-seatsocc.

AT END OF connid.

SUM.

ULINE.

WRITE: / 'Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

SKIP.

ENDAT.

AT END OF carrid.

SUM.

ULINE.

WRITE: / 'Carrier Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

NEW-PAGE.

ENDAT.

AT LAST.

SUM.

WRITE: / 'Overall Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

ENDAT.

ENDLOOP.

Rewads if helpful