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

DELETE

Former Member
0 Likes
1,039

Hi all

I have data like

matnr erdat

10000 12/2/2007

10000 14/2/2007

10001 14/2/2007

I want only the maximum value. If I am using max function i m getting 00.00.0000..

plz help me...

1 ACCEPTED SOLUTION
Read only

former_member404244
Active Contributor
0 Likes
1,014

Hi,

sort the internal table..

sort itab by matnr descending..

Now the first record will be the maximum one..in ur case it will be 10001.

Regards,

Nagaraj

11 REPLIES 11
Read only

former_member404244
Active Contributor
0 Likes
1,015

Hi,

sort the internal table..

sort itab by matnr descending..

Now the first record will be the maximum one..in ur case it will be 10001.

Regards,

Nagaraj

Read only

Former Member
0 Likes
1,014

Sort your table in Desending order on both the fields. and read first line form the same table.

Read only

0 Likes
1,014

But My Output is like :

matnr erdat

10000 14/2/2007

10000 12/2/2007

Read only

0 Likes
1,014

Hi Ankitha,

Select Single MAX( ERDAT ) from DBTABLE into <Structure> where....

Regards,

Satish

Read only

0 Likes
1,014

Hi...

If I am using MAX function it gives me 00.00.0000 value...

Read only

0 Likes
1,014

Hi Ankita,

Check this code. It's working fine.

SELECT MAX( ERSDA ) FROM MARA INTO ITAB-ERDAT .

here i am selecting max of ersda from mara and put it into the internal table variable.

Regards

Manoj Kumar

Read only

Former Member
0 Likes
1,014

Hi,

If you are trying to fetch database table, check the below code

Select erdat into l_f_erdat

from dtab

UP TO 1 ROWS

where condtion ....

order by ERDAT descending.

endselect.

Data will be sorted in descending order and will give u the recent date.

Read only

former_member402443
Contributor
0 Likes
1,014

Hi Ankita,

Check this program .

TYPES : BEGIN OF ty_tab,

matnr LIKE mara-matnr,

erdat LIKE mara-ersda,

END OF ty_tab.

DATA : itab TYPE STANDARD TABLE OF ty_tab INITIAL SIZE 0 WITH HEADER LINE.

START-OF-SELECTION.

MOVE '10000' TO itab-matnr.

MOVE '20070212' TO itab-erdat.

APPEND itab.

MOVE '10000' TO itab-matnr.

MOVE '20070214' TO itab-erdat.

APPEND itab.

MOVE '10001' TO itab-matnr.

MOVE '20070214' TO itab-erdat.

APPEND itab.

Sort itab by matnr descending erdat descending.

read TABLE itab index 1.

*Printed the maximum value

WRITE 😕 itab-matnr , itab-erdat.

This might will solve your problem.

Reward points,if useful.

Thanks

Manoj Kumar

Read only

Former Member
0 Likes
1,014

Hi,

after fetching data from database uasing select stmt you just apply sort ooperation on that internal table .but

first give erdat and then matnr.

select ...

sort itab by erdat descennding matnr ascending.

or you just try this on your reqt

sort itab by erdat matnr descennding .

Regds

Sivaparvathi

Please reward points if helpful.................

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
1,014

Hi,

Try this code.

tables mara.

data v_ersda type mara-ersda.

select max( ersda ) into v_ersda from mara.

write v_ersda.

Read only

Former Member
0 Likes
1,014

Can you try the below query for your requirement.

select single max( DISTINCT matnr ) max( ersda ) into (lv_matnr,lv_erdat)

from mara.