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 in Select Query

Former Member
0 Likes
751

Wanna select 5 fields (numeric) from a ztable based on date :

After selecting want to <b>add</b> them and move them to respective variable .

Say APP_SITES to gv_btr21,

SITE_CON to gv_btr22 etc.,

Query I wrote:

select APP_SITES SITE_CON LAND_COST TOTAL_CIP TOTAL_EXCL RES_NEED

from zreserve

into ( gv_btr21, gv_btr22, gv_btr24, gv_btr23, gv_btr26, gv_btr30 )

where erdat in s_pper.

Wanna select 5 fields (numeric) from a ztable based on date :

After selecting want to <b>add</b> them and move them to respective variable .

Say APP_SITES to gv_btr21,

SITE_CON to gv_btr22 etc.,

Query I wrote:

select APP_SITES SITE_CON LAND_COST TOTAL_CIP TOTAL_EXCL RES_NEED

from zreserve

into ( gv_btr21, gv_btr22, gv_btr24, gv_btr23, gv_btr26, gv_btr30 )

where erdat in s_pper.

4 REPLIES 4
Read only

Former Member
0 Likes
692

Hi Mohan,

You can use the SUM command in the select query ..

Just refer this link in SAP Library..

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3990358411d1829f0000e829fbfe/content.htm

Also go through the program <b>demo_select_group_by</b>.

In that instead of MAX(carrid) , just type SUM(CARRID) and find out the results.

Hope you got me..

Regards,

SP.

Read only

Former Member
0 Likes
692

Hi,

select APP_SITES SITE_CON LAND_COST TOTAL_CIP TOTAL_EXCL RES_NEED

from zreserve

into ( gv_btr21, gv_btr22, gv_btr24, gv_btr23, gv_btr26, gv_btr30 )

where erdat in s_pper.

w_total = w_total + gv_btr21 + gv_btr22 ... + gv_btr30

endselect.

Or you can declare a internal table and then dump the data into the table and thnen loop at the table and do the sum.

Regards,

Ravi

Read only

Former Member
0 Likes
692

HI Mohan

You have to use Group By to obtain the sum for each fields seperately.

i.e seperate query for each fields.

regards

kishore

Read only

Bema
Active Participant
0 Likes
692

select sum( APP_SITES ) sum( SITE_CON ) sum( LAND_COST ) sum( TOTAL_CIP ) sum( TOTAL_EXCL ) sum( RES_NEED )

from zreserve

into (gv_btr21,gv_btr22,gv_btr24,gv_btr23, gv_btr26, gv_btr30)

where erdat in s_pper.