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: 

Is it possible to use aggregation function in SQ Sap query?

Former Member
0 Kudos
615

I need to create a sap query like using SELECT MAX(begda) statement.

Please teach me how...

Thank u in advance..

3 REPLIES 3

Former Member
0 Kudos
273

Hi,

you can use aggeragate functions in the SQL statements in ABAP. for your reference please check the below code snippet.


data: i_mara type standard table of mara.
select max( matnr ) from mara into table i_mara.

Regards,

Prabhu.

Former Member
0 Kudos
273

Hi Ella,

You can very well use the aggregate functions in sql which is usually a performance tuning technique.

A calculation that is made on several records or cells of data. SUM, AVG, MAX, MIN and COUNT are examples of aggregate functions that are used in spreadsheets and database programs.

SELECT ( ( ] ...

MAX: returns the maximum value of the column

MIN: returns the minimum value of the column

AVG: returns the average value of the column

SUM: returns the sum value of the column

COUNT: counts values or lines as follows:

· COUNT( DISTINCT ) returns the number of different values in the column.

· COUNT( * ) returns the total number of lines in the selection.

Ex:    DATA: fldate LIKE sbook-fldate, 
      count  TYPE i, 
      avg    TYPE p DECIMALS 2, 
      max    TYPE p DECIMALS 2. 

SELECT fldate COUNT( * ) AVG( luggweight ) MAX( luggweight ) 
       FROM sbook 
       INTO (fldate, count, avg, max) 
       WHERE carrid = 'LH' AND 
             connid = '0400' 
       GROUP BY fldate. 
  WRITE: / fldate, count, avg, max. 
ENDSELECT.

For further info:

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

http://help.sap.com/abapdocu/en/ABAPSELECT_AGGREGATE.htm

Thanks and Regards

Srikant.P

Edited by: SRIKANTH P on May 27, 2009 9:41 AM

former_member222860
Active Contributor
0 Kudos
273

Pl. check the F1 help

tables: pa0001.

select max( begda ) from pa0001 into pa0001-begda.

write: pa0001-begda.