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: 

How to get the only the last raw of the table

0 Kudos

Hello All,

While fetching a table into internal table, how to get only the last record of the table.?

Thanks and Regards, Pradeep

9 REPLIES 9

Former Member
0 Kudos

First get the number of rows in table by using DESCRIBE command

DESCRIBE <> into a variable v_index

then use READ stmt as

READ table <tab> index v_index.

This will work out

Reward if helpful

Former Member
0 Kudos

Hi,

Get the number of rows using the DESCRIBE statement and then use READ TABLE ..INDEX..

Ex..

DESCRIBE TABLE ITAB.

READ TABLE ITAB INDEX sy-tfill.

Thanks

Naren

0 Kudos

 
SELECT COUNT(*)
  FROM DBTAB
  INTO v_index.
 
SELECT *
  FROM DBTAB
  INTO TABLE itab.
 
READ TABLE itab INTO x_tab INDEX V_INDEX.

varma_narayana
Active Contributor
0 Kudos

hi Pradeep..

Try this way.

SELECT <FIELDS> FROM dbtable INTO table ITAB.

DESCRIBE TABLE ITAB.

read table itab INDEX sy-tfill. "Last record

REWARD IF HELPFUL.

Former Member
0 Kudos

Hi Pradeep,

Use this..

DESCRIBE TABLE ITAB.

READ TABLE ITAB INDEX sy-tfill.

Reward if Useful.

Regards,

Chitra

Former Member
0 Kudos

hi,

use this...

<b>DESCRIBE TABLE ITAB.

READ TABLE ITAB INDEX sy-tfill.</b>

With RGds,

S.Barani

0 Kudos

I hope following code will solve your problem.

DATA : it_bseg TYPE TABLE OF bseg,

x_bseg TYPE bseg,

v_index TYPE i.

SELECT COUNT(*)

FROM bseg

INTO v_index.

SELECT *

FROM bseg

INTO TABLE it_bseg.

READ TABLE it_bseg INTO x_bseg INDEX V_INDEX.

First SELECT will give you the number of rows in a table in v_index. Second SELECT will fetch all table data and then READ will give you the last record of the table in a structure x_bseg.

Reward points if the answer is helpful.

Former Member
0 Kudos

Hi Pradeep,

Suppose your table is T549A.

<b>check the below code.</b>

data wa like t549a.

data itab like t549a occurs 0 with header line.

select * from t549a into wa.

move-corresponding wa to itab.

endselect.

append itab.

*So itab contains the last record of the given selections.

Former Member
0 Kudos

select * from <table>

into wa_tab

upto 1 rows order descending by <key field>.

this will give u the last record.

*reward if solved*