‎2008 Jan 25 8:11 AM
Hi,
How to find the total number of records in a database table? and how to fetch the last record?
Regards,
Kalaivani P
‎2008 Jan 25 8:13 AM
Hi,
To find out total number of records in a database table use Function module..TABLECOUNT
and in this one Pass Table name and client number as input
‎2008 Jan 25 8:16 AM
Use SY-DBCNT system varaible
sy-dbcnt -Nunber of records in database table
To get the last record use describe statment.
data: lv_line type i.
Describe table itab lines lv_line.
read table itab into wa_itab index lv_line.
Rewards if useful.
‎2008 Jan 25 8:27 AM
data : l_count(10).
select count(*) from ( table ) into l_count.
l_count will be the last record number
But reading the last record from the database table you need to get those in one internal table and later
read table itab with index l_count.
‎2008 Jan 25 9:25 AM
‎2008 Jan 25 10:43 AM
Hi,
To get the last record from the table use SY_DBCNT
This will give the database count ( number of records in the table ).
Read the last record with the index as SY-DBCNT values.
Select * from table into itab.
lv_lines = sy-dbcnt.
read table itab into wa index lv_lines.
In this code the wa contains the last record of the table.
Hope this clarifies you
Reward points if helpful
‎2008 Jan 25 8:27 AM
use system field
sy-dbcnt.
u can use the last value of the system field to get the value of the last record in the dtabase table
rewrd if useful
‎2008 Jan 25 8:28 AM
Hi,
U can get the totl number of records by this syntax..
SELECT COUNT(*) FROM ztable INTO variable.
Regards,
Nagaraj
‎2022 Feb 21 8:51 AM
SY-DBCNT is used to get the number of records in the table. Sort the table descending order and on that read the table index 1, then you can retrieve the last records in the table.