09-08-2008 2:15 PM
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.
09-08-2008 2:32 PM
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
09-08-2008 2:37 PM
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
09-08-2008 3:13 PM
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.
09-10-2008 6:53 AM
HI shabeer,
Use the F1 help to get the complete information on SUM.
-Luck,
Bhumika
09-10-2008 9:37 AM
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.
09-27-2008 5:43 AM