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: 

Count number of rows in table

Former Member
0 Kudos

Hi!

1. How can you through ABAP and select statements count the number of rows in one table?

2. I want to read all rows from one table to an internal table. Can this be done dynamically or do I first have to count the number of rows in the table and then declare an internal table with the number of rows counted.

regards

Baran

1 ACCEPTED SOLUTION

dani_mn
Active Contributor
0 Kudos

HI,

No you don't have to count number of rows first, Internal table size will increase dynamically. you have to declare this with initial size like this.

<b>data: itab type standard table of bkpf initial size 0.

SELECT * FROM bkpf into table itab.</b>

All values from bkpf will be inserted into table internal table itab.

Regards,

5 REPLIES 5

Former Member
0 Kudos

use

<b>sy-dbcnt</b>

Former Member
0 Kudos

Hi !

To count the number of lines of a database table

you could use the select count ... statement.

See online-help for that...

Regards

Rainer

Some points would be nice if that helped a bit.

Former Member
0 Kudos

Hi,

1. Select count(*)... is used to get count from table.

2. Select <field list> from <table> into table <internal table> is used to get full data of table into internal table.

3. describe table <internal table> lines <var> used to count the no. of lines in internal table.

Regards,

Prasanth

dani_mn
Active Contributor
0 Kudos

HI,

No you don't have to count number of rows first, Internal table size will increase dynamically. you have to declare this with initial size like this.

<b>data: itab type standard table of bkpf initial size 0.

SELECT * FROM bkpf into table itab.</b>

All values from bkpf will be inserted into table internal table itab.

Regards,

Former Member
0 Kudos

1.

select COUNT(*) from table.

then SY-DBCNT field will contain no of records

2.

no need, if you mention INTO TABLE all data to be populated to your internal table. no need to findout no of records.

Regards

srikanth