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

Select Max date value from a tabel

anuradha_wijesinghe
Participant
0 Likes
40,732

hello everyone,

I have a table like bellow.

    

KALNRKADKYPOSNRMATNRWERTN
10020025001.04.2013960012200.02
10020025001.05.2013960012200.02
10020025001.06.2013960012200.02
10020025001.07.2013960012200.02
10020025001.04.20131060009200.02
10020025001.05.20131060009200.02
10020025001.06.20131060009200.02
10020025001.07.20131060009200.02

So I need to get the maximum date value in this table (01.07.2013) . So how can I get this value using a SELECT command in ABAP.

hello everyone,

I have a table like bellow.

    

KALNRKADKYPOSNRMATNRWERTN
10020025001.04.2013960012200.02
10020025001.05.2013960012200.02
10020025001.06.2013960012200.02
10020025001.07.2013960012200.02
10020025001.04.20131060009200.02
10020025001.05.20131060009200.02
10020025001.06.20131060009200.02
10020025001.07.20131060009200.02

So I need to get the maximum date value in this table (01.07.2013) . So how can I get this value using a SELECT command in ABAP.

15 REPLIES 15
Read only

Arun_Prabhu_K
Active Contributor
0 Likes
13,732

Hello Anuradha.

Use MAX function.

select max( COLUMN ) from TABLE into dt.

Refer ABAPDOCU tcode.

Regards.

Read only

former_member209120
Active Contributor
0 Likes
13,732

Hi Anuradha,

See this link http://scn.sap.com/thread/709182

Read only

Former Member
0 Likes
13,732

DATA d type d.

select max( KADKY ) from TABLE into d.

in this situation DAta store in kadky table as yyyymmdd

so its pick up maximum on base of amount.

Read only

Former Member
0 Likes
13,732

Hi,

A simple example..

Replace xxx by ur structure name & 'YYY' table  name.

DATA : d type s_date.

TYPES: BEGIN OF ty_xxx,

              KADKY TYPE S_DATE,

              END OF ty_xxx.

DATA: t_xxx TYPE TABLE OF ty_xxx,

      x_xxx TYPE ty_xxx.

SELECT KADKY from YYY INTO TABLE t_xxx.





IF d is INITIAL.

     LOOP AT t_sflight INTO x_sflight.
        d x_xxx-KADKY.
    ENDLOOP.

ELSE.

    LOOP AT  t_xxx INTO  x_xxx.

     IF d >  x_xxx-
KADKY .

        d x_xxx-
KADKY

.
    ENDIF.

    ENDLOOP.

ENDIF.

WRITE d.

Regards,

Farid.

Read only

sivaganesh_krishnan
Contributor
0 Likes
13,732

Hi anuradha,

Use Max Function to get the maximum value of column in table.

I have tried this,

select  MAX( MATCH_DATE -->( Column) )

           FROM zapt_header_tb---> (Table)

           into date.

if sy-subrc EQ 0.
    WRITE date.
    ENDIF.

This will give the maximum date .

Regards,

Sivaganesh

Read only

sandeep_ramesh88
Explorer
0 Likes
13,732

Hi,

Either try as praveen suggested or

select the data required into an internal table.

Sort the internal table by KADKY descending.

Read the first line from the internal table.

Thanks.

Read only

Former Member
0 Likes
13,732

Hi,

select kalnr max(kadky) posnr matnr wertn

           from some_table

           into some_other_table

          where some_condition.

Read only

Former Member
0 Likes
13,732

Hi,

First declare a variable of type sy-datum.

DATA : v_date TYPE sy-datum.

Then use the below select query to fetch the maximum date from the table.

While writng the select query please take  care of the spaces between the parentheses.

SELECT MAX( ADKY ) FROM <table_name> INTO v_date.

WRITE : v_date.

Regards,
Riju Thomas.

Read only

former_member308418
Participant
0 Likes
13,732

Hi,

I guess you need to get max date value from your internal table. If this is the case then simply follow it,

 

SORT itab by kadky DESCENDING.

   READ TABLE itab INDEX 1.

  

   WRITE :/ itab-kadky.

by this you will get the max field value from your internal table.

Read only

0 Likes
13,732

Hi , Please check the code below,,

TYPES: BEGIN OF TY_001,    

    KALNR   TYPE TABLE-KALNR,

   KADKY TYPE TABLE-KADKY,

   POSNR TYPE TABLE-POSNR,

   MATNR TYPE TABLE-MATNR,

   WERTN TYPE TABLE-WERTN,

TYPES:END OF TY_001., 




DATA LS_TABLINE TYPE TY_001.

SELECT  KALNR  MAX(KADKY)  POSNR  MATNR  WERTN

INTO LS_TABLINE                          "--->LOCAL STRUCTURE .

FROM  <TABLE>

WHRER <ANY CONDITIONS>

POINTS PLEASE.....

Read only

Former Member
0 Likes
13,732

Hi,

If you have data in data base table use

Read only

0 Likes
13,732

Hi,

To fetch only date value

SELECT KADKY FROM <dbtable> INTO LV_KADKY WHERE <field> = cond1 ORDER BY KADKY DESCENDING.

ENDSELECT.

to fetch a single record.

SELECT KALNR  KADKY  POSNR  MATNR  WERTN FROM <dbtable> INTO WA_1 WHERE <field> = cond1 ORDER BY KADKY DESCENDING.

ENDSELECT.

Regards,

Lokesh

Read only

RaymondGiuseppi
Active Contributor
0 Likes
13,732

Did you read Abap online documentation like http://help.sap.com/abapdocu_731/en/abapselect_aggregate.htm or transaction ABAPDOCU or F1 on source editor.

Regards,

Raymond

Read only

Former Member
0 Likes
13,732

Hi Anuradha,

     Try this query...

select max(field name) from table name into wa-fieldname

where condition......

sure this will solve...

Read only

Former Member
0 Likes
13,732

This message was moderated.