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

Sum fields in a sql query

roberto_falk
Product and Topic Expert
Product and Topic Expert
0 Likes
2,950

Hi,

somebody knows how to sum two columns of a table as a result of an abap sql query. I know that is possible to do it in a native sql like


select f.seatmax max, f.seatfree free, f.seatmax - f.seatfree seatoccu from flights

Tks

Roberto Falk

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,433

Hi Roberto,

You can not do this in Open sql.

7 REPLIES 7
Read only

Former Member
0 Likes
1,434

Hi Roberto,

You can not do this in Open sql.

Read only

Former Member
0 Likes
1,433

Hi Roberto ,

Here is a sample code which does some thing similar

Data : v_LABST type LABST ,
       v_umlme type umlme.

start-of-selection.

       select sum( labst ) sum( umlme )
         into (v_labst , v_umlme)
         from mard.

write:/ v_labst , v_umlme.

Regards

Arun

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
1,433

Hi,

It's not possible.

But alternatively,you need to write select statement fro the two fields (sa y A and B) and then loop the internal table to get (A + B).

Read only

roberto_falk
Product and Topic Expert
Product and Topic Expert
0 Likes
1,433

This is the problem... I don't want to interate the internal table after the select.

Tks all.

Roberto

Read only

0 Likes
1,433

Hi,

select sum( A ) from db into v1.

select sum( B ) from db into v2.

v = v1 + v2.

write v.

Message was edited by:

Jayanthi Jayaraman

Read only

roberto_falk
Product and Topic Expert
Product and Topic Expert
0 Likes
1,433

No, this is not my idea.... I wanna the sum of each column... not the total sum of the table...

like


select a, b, a+b from dual

Tks

Roberto Falk

Read only

0 Likes
1,433

Hi,

select A B from db into corresponding fields of wa.

wa-c = a + b.

append wa to itab.

endselect.

I don't think there is some way other than iteration.