10-10-2007 6:16 AM
Hello All,
While fetching a table into internal table, how to get only the last record of the table.?
Thanks and Regards, Pradeep
10-10-2007 6:19 AM
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
10-10-2007 6:20 AM
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
10-10-2007 6:21 AM
SELECT COUNT(*)
FROM DBTAB
INTO v_index.
SELECT *
FROM DBTAB
INTO TABLE itab.
READ TABLE itab INTO x_tab INDEX V_INDEX.
10-10-2007 6:26 AM
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.
10-10-2007 6:30 AM
Hi Pradeep,
Use this..
DESCRIBE TABLE ITAB.
READ TABLE ITAB INDEX sy-tfill.
Reward if Useful.
Regards,
Chitra
10-10-2007 6:32 AM
hi,
use this...
<b>DESCRIBE TABLE ITAB.
READ TABLE ITAB INDEX sy-tfill.</b>
With RGds,
S.Barani
10-10-2007 6:34 AM
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.
10-10-2007 8:00 AM
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.
10-10-2007 8:04 AM
select * from <table>
into wa_tab
upto 1 rows order descending by <key field>.
this will give u the last record.
*reward if solved*