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 Table

Former Member
0 Likes
880

Hi,

How to find the total number of records in a database table? and how to fetch the last record?

Regards,

Kalaivani P

8 REPLIES 8
Read only

former_member188829
Active Contributor
0 Likes
833

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

Read only

Former Member
0 Likes
833

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.

Read only

Former Member
0 Likes
833

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.

Read only

0 Likes
833

How to fetch the last record from the database table?

Read only

0 Likes
833

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

Read only

Former Member
0 Likes
833

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

Read only

former_member404244
Active Contributor
0 Likes
833

Hi,

U can get the totl number of records by this syntax..

SELECT COUNT(*) FROM ztable INTO variable.

Regards,

Nagaraj

Read only

shivani08
Participant
0 Likes
833

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.