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: 

max aggregate functions

sudhakara_reddy4
Participant
0 Kudos

Hi,

in VBAK table i need latest date entered i.e max date value, field is ERDAT

can anybody write syntax for this

select max( ERDAT )

from vbak

into maxfeild

group by ERDAT.

endselect.

i think it is wrong can anybody write correct syntax.

7 REPLIES 7

Former Member
0 Kudos

Try using this code.

IF NOT it_ekpo[] IS INITIAL.

SELECT ebeln

ebelp

etenr

eindt

menge

wemng

FROM eket

INTO TABLE it_eket

FOR ALL ENTRIES IN it_ekpo

WHERE ebeln EQ it_ekpo-ebeln

AND ebelp EQ it_ekpo-ebelp.

IF sy-subrc EQ 0.

SORT it_eket BY ebeln ASCENDING

ebelp ASCENDING

eindt DESCENDING.

DELETE ADJACENT DUPLICATES FROM it_eket COMPARING ebeln

ebelp.

ENDIF.

ENDIF.

check the below link :

Thanks

Seshu

Message was edited by:

Seshu Maramreddy

Former Member
0 Kudos

Hi Sudhakar,

Check this syntax

select max( ERDAT )

from vbak

into maxfeild.

<b>*group by ERDAT.

*endselect.

</b>

1) If you specify aggregate functions together with one or more database fields in a SELECT clause, all database fields not used in one of the aggregate functions must be listed in the GROUP-BY clause . Here, the result of the selection is a table.

2) If only aggregate functions occur in the SELECT clause, the result of the selection is a single record. Here, the SELECT command is not followed later by an ENDSELECT .

Thanks,

Vinay

Former Member
0 Kudos

This is the correct one

data maxfield type vbak-erdat .

select max( ERDAT )

from vbak

into maxfield.

Reawrd if useful

Former Member
0 Kudos

select max( ERDAT )

into maxfeild

from vbak.

regards

shiba dutta

kesavadas_thekkillath
Active Contributor
0 Kudos

if u only want the max date entered.

try this,

select single max ( field ) into <table> from <database> up to 1 rows.

if there is chances of so many entries for the maximum date.

try this

select kunnr max ( field ) into <table> from <database>

reward if usefull

kesavadas_thekkillath
Active Contributor
0 Kudos

or u can use this too..

select single date from vbak into <itab> order by date descending.

but using order by is a bit worst than using max.

try using max for performance

0 Kudos

hey,

as Seshu Maramreddy said, thats the best way.

First u should fill the itab, then sort it and after