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

SQL QUERY FOR COUNT

Former Member
0 Likes
1,304

HI all,

I need to know the no of records in a table in sap..

can anybody help on this how to get the count of the records.?

thanks in advance

kp

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,178

Hi KP,

You can code it this way

data var type i.
select count(*) from ztable into var.
write : var.

Here

var

gives you teh number of records.

The advantage of this is that you don't have to bring all the records into the application server, just to count the records. The n/w traffic is hence reduced.

Regards

Anil Madhavan

6 REPLIES 6
Read only

Former Member
0 Likes
1,178

describe table int_table lines v_lines. " if it is internl table

table : goto se16 ->enter table -> enter->click on number of entries

Read only

0 Likes
1,178

I am writing a report. in that i need to get the no of records( count) as output.

that table i am using is database table. and i need to store that no of record value into a variable(count).

Pls provide me the query syntax

Thanks in advance

KP

Read only

0 Likes
1,178

use describe after select query .

data : v_lines type i.

describe table itab lines v_lines.

here itab is the internal table

Read only

Former Member
0 Likes
1,178

Hi KP,

You can fetch the data of the database table into an internal table using SELECT statement and then find the no: of entries of the internal table using DESCRIBE statement.

select * from sflight into table itab.

describe table itab lines count.

Regards,

SP.

Read only

Former Member
0 Likes
1,179

Hi KP,

You can code it this way

data var type i.
select count(*) from ztable into var.
write : var.

Here

var

gives you teh number of records.

The advantage of this is that you don't have to bring all the records into the application server, just to count the records. The n/w traffic is hence reduced.

Regards

Anil Madhavan

Read only

Former Member
0 Likes
1,178

hi

sy-dbcnt contains the no. of database records fetched by a select

select * from dbtab into table itab where <cond>.

if sy-subrc eq 0.

write sy-dbcnt.

endif.

if helpful, reward

Sathish. R