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 in group by

Former Member
0 Kudos

kindly tell me why max date not showing when i m using group by.

data :

BEGIN OF GetMaxDate OCCURS 1,

matnr like a305-matnr, " matnr

datab like a305-datab, " validFrom

knumh like a305-knumh , " RecNo

kunnr like a305-kunnr, " CustomerNo

vtweg like a305-VTWEG,"channel

*PLTYP like a304-pltyp ," Pricelist type

END OF GetMaxDate.

SELECT MATNR MAX( DATAB ) as ValidFrom from A305 INTO CORRESPONDING FIELDS OF TABLE GETMAXDATE GROUP BY MATNR

but result shows date like 00:0000:00

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Haris.

Just copy paste this code and check now.

it is working fine

EPORT ztn_test .
"Changes are mentioned

data :
BEGIN OF GetMaxDate OCCURS 1,
matnr like a305-matnr, 
datab type sy-datum, "change here
knumh like a305-knumh ,
kunnr like a305-kunnr, 
vtweg like a305-VTWEG,
*PLTYP like a304-pltyp ,
END OF GetMaxDate.

"as ValidFrom remove this and use ( as datab ) 
SELECT MATNR max( DATAB ) as datab  from A305 INTO CORRESPONDING FIELDS OF TABLE GETMAXDATE GROUP BY MATNR
.

Edited by: tahir naqqash on Mar 11, 2009 4:15 PM

7 REPLIES 7

Former Member
0 Kudos

Hi,

Get the data into GETMAXDATE and sort the table GETMAXDATE be DATAB DESCENDING.

Read the first record with index 1. you get the MAX date.

0 Kudos

i think its due to strucuture which i define. kindly help me

0 Kudos

Hi,

Am not sure thou but give this a try.

select matnr max(datab) as ValidFrom from A305 
	into corresponding fields of table getmaxdate 
		where matnr eq 
			(select matnr from A305 into temp).

Regards,

Sakkthiss.R

Former Member
0 Kudos

Hi,

Sort the internal table in descending oreder as per the date..

The first record will have the maximum date.

You can fetch the value then easily

Regards,

Sakkthiss.R

Former Member
0 Kudos

SELECT MATNR MAX( DATAB ) as ValidFrom from A305 INTO CORRESPONDING FIELDS OF TABLE GETMAXDATE GROUP BY MATNR

ORDER BY datab descending.

check if it works now after adding order by clause.

кu03B1ятu03B9к

0 Kudos

problem still remain same..i have 10 material .i need each with max date. but result still like this

matnr datab

1 00:00:0000

2 00:00:0000

3 00:00:0000

4 00:00:0000

5 00:00:0000

6 00:00:0000

Former Member
0 Kudos

Hi Haris.

Just copy paste this code and check now.

it is working fine

EPORT ztn_test .
"Changes are mentioned

data :
BEGIN OF GetMaxDate OCCURS 1,
matnr like a305-matnr, 
datab type sy-datum, "change here
knumh like a305-knumh ,
kunnr like a305-kunnr, 
vtweg like a305-VTWEG,
*PLTYP like a304-pltyp ,
END OF GetMaxDate.

"as ValidFrom remove this and use ( as datab ) 
SELECT MATNR max( DATAB ) as datab  from A305 INTO CORRESPONDING FIELDS OF TABLE GETMAXDATE GROUP BY MATNR
.

Edited by: tahir naqqash on Mar 11, 2009 4:15 PM