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 statement

Former Member
0 Likes
1,032

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,012

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.

9 REPLIES 9
Read only

Former Member
0 Likes
1,012

select max ( date ) from <database table> where <Condition>.

Regards,

Ravi Kanth Talagana

Read only

Former Member
0 Likes
1,012

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.

Read only

Former Member
0 Likes
1,012

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. 

Read only

Former Member
0 Likes
1,012

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

Read only

Former Member
0 Likes
1,012

Hello,


select single * from <table> into <ls_table> order by final_date descending .

Regards,

Read only

Former Member
0 Likes
1,012

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.

Read only

Former Member
0 Likes
1,012

thanks

Read only

Former Member
0 Likes
1,013

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.

Read only

Former Member
0 Likes
1,012

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.