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

max aggregate functions

sudhakar196
Participant
0 Likes
1,366

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
Read only

Former Member
0 Likes
953

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

Read only

Former Member
0 Likes
953

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

Read only

Former Member
0 Likes
953

This is the correct one

data maxfield type vbak-erdat .

select max( ERDAT )

from vbak

into maxfield.

Reawrd if useful

Read only

Former Member
0 Likes
953

select max( ERDAT )

into maxfeild

from vbak.

regards

shiba dutta

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
953

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

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
953

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

Read only

0 Likes
953

hey,

as Seshu Maramreddy said, thats the best way.

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