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: 

How can i use SUM aggregate in select query?

Former Member
0 Kudos

HI,

GURUS,

How can i use SUM function in Select Query and i want to store that value into itab.

for ex:

TABLES: vbap.

types: begin of ty_vbap,

incluse type vbap,

sum type string,

end of ty_vbap.

data: i_vbap type TABLE OF ty_vbap,

w_vbap type ty_vbap.

SELECT sum(posnr) FROM vbap into table i_vbap up to 5 rows.

(or)

SELECT sum(posnr) FROM vbap into table i_vbap group by vbeln.

loop at i_vbap into w_vbap

" which variable have to use to display summed value.

endloop.

if above code is not understandable pleas give ome sample code on above query.

Thank u,

shabeer ahmed.

6 REPLIES 6

Former Member
0 Kudos

Hi,

Check this sample code.

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.

Regards,

Sravanthi

Former Member
0 Kudos

Hello Shabeer,

Can you tell me what you requirement is? or Further explain what you are trying to accomplish from this SUM query?

Regards,

C

asik_shameem
Active Contributor
0 Kudos

Hi

See this example.

The following query will sum-up the given field (ZMENG - Quantity) in the table VBAP for 10 rows and stores the total value (total qty for 10 records) into variable gv_total.

DATA: gv_total TYPE vbap-zmeng.

SELECT SUM( zmeng ) FROM vbap INTO gv_total UP TO 10 ROWS.

Former Member
0 Kudos

HI shabeer,

Use the F1 help to get the complete information on SUM.

-Luck,

Bhumika

Former Member
0 Kudos

SELECT - aggregate

Syntax

... { MAX( [DISTINCT] col )

| MIN( [DISTINCT] col )

| AVG( [DISTINCT] col )

| SUM( [DISTINCT] col )

| COUNT( DISTINCT col )

| COUNT( * )

| count(*) } ... .

SUM( [DISTINCT] col ) Determines the sum of the content of the column col in the resulting set or in the current group. The data type of the column has to be numerical.

Former Member
0 Kudos

Thank You