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

count

Former Member
0 Likes
890

hi

i want to count the no of rows in a specified table.

but i know to count the number of rows in a mara,lfa1 etc.,

i want the number of rows in a table in which a table is specified at runtime.i.e)in parameters wat table is to be specified that table fields is to be count.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
842
REPORT ABC MESSAGE-ID ZZ.

parameters : P_TAB LIKE DD02L-TABNAME.

DATA : V_CNT TYPE I.

SELECT COUNT(*) FROM (P_TAB) INTO V_CNT.

WRITE : V_CNT.
7 REPLIES 7
Read only

dustyplanet
Active Participant
0 Likes
842

Try this code...

PARAMETERS: tname TYPE dd02l-tabname.

DATA: count TYPE i.

START-OF-SELECTION.
  SELECT COUNT( * ) INTO count FROM (tname).
  WRITE:/ 'No of records in table ', tname,' is ', count.

Hope this helps

Regards,

Dushyant Shetty

Read only

Former Member
0 Likes
843
REPORT ABC MESSAGE-ID ZZ.

parameters : P_TAB LIKE DD02L-TABNAME.

DATA : V_CNT TYPE I.

SELECT COUNT(*) FROM (P_TAB) INTO V_CNT.

WRITE : V_CNT.
Read only

Former Member
0 Likes
842

Hi

Try this:

PARAMETER P_TABLE(30).

DATA: COUNT TYPE I.

SELECT COUNT( * )
       INTO COUNT
       FROM (P_TABLE).

WRITE COUNT.

Max

Read only

Former Member
0 Likes
842

hi,

data v_lines type i,

describe table <itab> lines v_lines.

v_lines contains the number of records.

rewards if useful;

regards,

nazeer

Read only

Former Member
0 Likes
842

Hi Manjula,

Try using this:

1. For an internal table.

Data: v_count TYPE i.

DESCRIBE TABLE i_itab LINES v_count.

Now v_count contains the number of rows in the table i_itab.

2. For a database table.

After u write a select on a database table. Check the value of sy-dbcnt. This contains the number of records fetched from the select query.

Regards,

Pradeep Chintala.

Read only

dev_parbutteea
Active Contributor
0 Likes
842

HI,

use describe tablename lines integer_variable.

Regards.

Read only

Former Member
0 Likes
842

Hi Manjula,

here a short example:

tables: marc.

FIELD-SYMBOLS: <FS>.

data: begin of itab occurs 0.

include structure marc.

data: end of itab.

*

data: column like sy-index.

data: row like sy-tabix.

*

DO 1000 TIMES.

ASSIGN COMPONENT SY-INDEX OF STRUCTURE Itab TO <FS>.

IF SY-SUBRC <> 0. EXIT. ENDIF.

column = column + 1.

ENDDO.

write: / column.

*

select * from marc into table itab up to 100 rows.

describe table itab lines row.

write: / row.

*

select count( * ) from marc.

write: / sy-dbcnt.

hope it helps.

Regards, Dieter