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

Database Select - Regdg.

Former Member
0 Likes
687

Hi,

I want to read the last record in the Database Table. How to write such an select statement.I don't want to use Internal tables for this purpose. Is there any way.

regards,

Navneeth.K

1 ACCEPTED SOLUTION
Read only

aris_hidalgo
Contributor
0 Likes
649

Hi,

Please take a look at my example below.

tables: vbak.

select vbeln erdat

from vbak up to 1 rows

into (vbak-vbeln, vbak-erdat)

order by erdat descending.

write: vbak-vbeln, vbak-erdat.

In my example above, it gets the last record from VBAK table according to the date. Hope this helps...

P.S. Please award points if it helps...

5 REPLIES 5
Read only

Former Member
0 Likes
649

hi

try this

<b>DESCRIBE TABLE i_mvke LINES ws_lines.

READ TABLE i_mvke INTO wa_mvke INDEX ws_lines.</b>

You will have a latest record in wa_mvke

regards

ravish

<b>plz reward points if helpful</b>

Read only

0 Likes
649

Hi Ravish,

I dont want to use any internal tables , is there any other way.

regards,

Navneeth.K

Read only

0 Likes
649

Hi Navneeth,

Try this query

SELECT * FROM <tablename> LIMIT < last row number in the table>,-1.

Regards,

ANusha

Read only

Former Member
0 Likes
649

Hi,

As SAP uses internal tables to manipulate the data, i dont think you can directly get the last record from database table directly.

You can get the number of records directly using count(*) or getting sy-dbcnt.

Sandeep

Read only

aris_hidalgo
Contributor
0 Likes
650

Hi,

Please take a look at my example below.

tables: vbak.

select vbeln erdat

from vbak up to 1 rows

into (vbak-vbeln, vbak-erdat)

order by erdat descending.

write: vbak-vbeln, vbak-erdat.

In my example above, it gets the last record from VBAK table according to the date. Hope this helps...

P.S. Please award points if it helps...