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: 

Select Max date value from a tabel

anuradha_wijesinghe
Participant
0 Kudos

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

karun_prabhu
Active Contributor
0 Kudos

Hello Anuradha.

Use MAX function.

select max( COLUMN ) from TABLE into dt.

Refer ABAPDOCU tcode.

Regards.

former_member209120
Active Contributor
0 Kudos

Hi Anuradha,

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

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.

sivaganesh_krishnan
Contributor
0 Kudos

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

sandeep_ramesh88
Explorer
0 Kudos

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.

former_member215424
Active Participant
0 Kudos

Hi,

select kalnr max(kadky) posnr matnr wertn

           from some_table

           into some_other_table

          where some_condition.

Former Member
0 Kudos

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.

former_member308418
Participant
0 Kudos

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.

0 Kudos

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.....

former_member184958
Active Participant
0 Kudos

Hi,

If you have data in data base table use

0 Kudos

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

raymond_giuseppi
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi Anuradha,

     Try this query...

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

where condition......

sure this will solve...

Former Member
0 Kudos

This message was moderated.