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

fetch last record from database table

Former Member
0 Likes
622

hi,

how to fetch last record from database table.

plz reply earliest.

Regards,

Jyotsna

Moderator message - Please search before asking - post locked

Edited by: Rob Burbank on Dec 11, 2009 9:44 AM

4 REPLIES 4
Read only

Former Member
0 Likes
591

Hello,

Select single * from <table> order by <keyfield> desc.

Thanks

manish

Read only

Former Member
0 Likes
591

must be something with select..i tried but wasn't able to find...

selecting in descending order might not work...

select all the data..

describe the internal table.

and then read with index.

hope it helps

regards

Yadesh

Read only

Former Member
0 Likes
591

Hi Jyotsana,

Do as below :-

SELECT single FIELD1 FIELD2 from table into TABLE ITAB WHERE FIELD1 = 'VALUE'.

ENDSELECT.

LOOP AT ITAB into WA.

Do nothing....

ENDLOOP.

Here WA will be having the last record.

Regards

Abhii

Read only

0 Likes
591

abhi,

just imagine the table to be BSEG or FAGLFLEXA... then what would be performance of the code ?

any ways,

jyotsna, first check if you have a pattern to follow like if the primary key field have a increasing number range or it would be great if you find a date field which stores the inserted date or some thing..

you can select max or that field or order by descending using select single.

or get all data.. sort in descending order.(again you need some criteria like date).

read the first entry. using read itab index 1