‎2008 Apr 18 2:37 PM
hi
I have a database table in which i have two fields
startdate and enddate
suppose i have 10 records inmy database table i want to
01.01.2000 31.01.2000
01.02.2000 28.02.2000
and so on
and the last record is
01.10.2000 31.10.2000
now i want to write a select statement to retrieve the latest date ie the last record
can anyone help me in this
‎2008 Apr 18 2:47 PM
Check this..
select * from <table>
up to 1 rows
into wa
where condition
order by date descending.
endselect.
example: ---
data: wa type vbap.
select * from
vbap up to 1 rows
into wa
where vbeln eq '1234'
order by posnr descending.
endselect.
‎2008 Apr 18 2:39 PM
select max ( date ) from <database table> where <Condition>.
Regards,
Ravi Kanth Talagana
‎2008 Apr 18 2:41 PM
Write the select as :
select * from <table> into table itab
where startdate <= enddate
and enddate >= startdate.
if sy-subrc = 0.
sort itab by enddate descending.
endif.
‎2008 Apr 18 2:41 PM
hi,
do this way ....
select * from <table> into table itab where <conditions>.
if sy-subrc = 0.
sort itab by end_date descending.
read table itab index 1.
if sy-subrc = 0.
< this will give the latest end date record >
endif.
endif.
‎2008 Apr 18 2:45 PM
guys i know the way of getting the data in the internal table and sorting it
but is there any select single statement that i can apply here
‎2008 Apr 18 2:45 PM
Hello,
select single * from <table> into <ls_table> order by final_date descending .
Regards,
‎2008 Apr 18 2:47 PM
Hey Ram,u can use a macro : rp_provide_from_last to retrive latest record from the internal table.Lets say u r program flow is like this.
Tables : Pernr.
Infotypes : 0002.
Get pernr.
RP_PROVIDE_FROM_LAST P0002 SPACE PN-BEGDA PN-ENDDA.
IF PNP-SW-FOUND NE 1
REJECT.
ENDIF.
Hope u got it.If found useful Reward points.
‎2008 Apr 18 2:47 PM
‎2008 Apr 18 2:47 PM
Check this..
select * from <table>
up to 1 rows
into wa
where condition
order by date descending.
endselect.
example: ---
data: wa type vbap.
select * from
vbap up to 1 rows
into wa
where vbeln eq '1234'
order by posnr descending.
endselect.
‎2008 Apr 18 2:58 PM
hi ram
here is the query which will be help fl to u and also satisfy all test case
let ur table name is itab with headerline.
select startdate
enddate
into ( itab-startdate , itab-enddate )
from itab
where
startdate = max ( startdate )
enddate = max ( enddate ) .
if sy-subrc = 0 .
if startdate = enddate.
write:/ enddate.
elseif startdate is < enddate.
write:/ enddate.
endif.
Reward if helpfull.