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: 

total number of records in database table

Former Member
0 Kudos

hi,

how to know the total number of records in a database table?

thank you..

regards,

mae

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

if you are using this table then Sy-dbcnt will give no. of processed records.

You can also get the data in an Internal table and then use

DESCRIBE TABLE itab LINES v_l_total_lines.

This will give you no. of records in v_l_total_lines.

Regards,

Preeti

14 REPLIES 14

Former Member
0 Kudos

Hi

Use SY-DBCNT system varaible.

Pls Reward if Useful

Regards,

Preeti

0 Kudos

hi,

can you give me a sample code for that?

thank you,

regards,

mae

Former Member
0 Kudos

data: totno type i.

select count(*) from ztable into totno.

write:/ totno.

here you can use the system variable sy-dbcnt also....

Former Member
0 Kudos

HI,

DATA : ITAB LIKE MARA OCCURS 0 WITH HEADERLINE.

DATA : V_LINES LIKE SY-TABIX.

SELECT *

FROM MARA

INTO TABLE ITAB.

DESCRIBE TABLE ITAB LINES V_LINES.

WRITE : / V_LINES.

REWRD IF HELP FUL

RGDS

UMAKANTH

Former Member
0 Kudos

hi mae,

The following SAP SY structure variables can give u more info...

SAP SY Structure Variables

sy-datum -date

sy-uzeit -time

sy-tzone -hours behind Universial Standard Time

sy-uname -user

sy-langu -language

sy-sysid -system ID

sy-saprl -release number

sy-dbsys -database system

sy-opsys -operating system

sy-tcode -transaction code

sy-cprog -main

sy-repid -report id

sy-subrc -return code

sy-index -loop counter

sy-table -line index date

sy-fdpos -string location

sy-batch -background processing indicator

sy-dbcnt -Nunber of records in database table

sy-dynnr -current screen

sy-dyngr -current screen group

sy-pfkey -GUI status

sy-msgid -message ID

sy-msgty -message type

sy-msgno -message number

sy-msgv1...4-message

sy-uline -underline

sy-vline -vertical bar

sy-pagno -current page

sy-colno -current column

sy-linno -line number

sy-linct -line count

sy-cucol -cursor column position

sy-curow -curser row position

sy-winco -cursor window column position

sy-winro -cursor window row position

sy-tvar0...9 -text elements

Reward if useful.

Thank you,

Regards.

Former Member
0 Kudos

Hi,

if you are using this table then Sy-dbcnt will give no. of processed records.

You can also get the data in an Internal table and then use

DESCRIBE TABLE itab LINES v_l_total_lines.

This will give you no. of records in v_l_total_lines.

Regards,

Preeti

Former Member
0 Kudos

hi. Example program to display the number of records.

REPORT Z98168PROG5 .

DATA: itab TYPE STANDARD TABLE OF spfli,

wa LIKE LINE OF itab.

DATA: line(72) TYPE c,

list LIKE TABLE OF line(72).

line = ' CITYFROM CITYTO '.

APPEND line TO list.

SELECT DISTINCT (list)

INTO CORRESPONDING FIELDS OF TABLE itab

FROM spfli.

IF sy-subrc EQ 0.

LOOP AT itab INTO wa.

WRITE: / wa-cityfrom, wa-cityto.

ENDLOOP.

ENDIF.

Write : sy-dbcnt, 'Records found' .

Reg,

Prabakaran.S

Former Member
0 Kudos

Hi,

There are couple ways to find the no. of records in db table.

1. Select count(*) from table. It will gives you the no. of records present in that table.

2. After select statement you can use sy-dbcnt to get the no. of records retreived from the db table.

3. Describe statement with sy-tfill, will also give you the no. of records present in itab.

Thanks,

Sriram Ponna.

Former Member
0 Kudos

Hi mae,

This is kiran kumar.G.Plz execute the below code ur problem will be resolved..

code:

data: itab type standard table of mara with header line.

select * from mara into table itab.

write:sy-dbcnt.

Award points if helpful.

kiran kumar.G

Have a Nice Day..

Former Member
0 Kudos

Hi ,

Use Select count(a promary key field) , this will give you the number of records.

Regards,

Arun

Former Member
0 Kudos

Hi,

The approach u want to follow to get the total no. of lines of DB table depends actually on the req.

Using the aggregate fxn Select Count(*) will be expensive if u need to process the data after u check the no. of records. If u jst need to check the no. then u can u use this.

And if use Describe table (it works only for internal tables) u need to fetch the data from DB whether or not u want to use it. So this will be expensive if u do not want to process this data.

Depending on the req, take a wise decision which method u want to go for.

Pls reward if helpful

Regards,

Preeti

Former Member
0 Kudos

SELECT * FROM zohdrocm

INTO TABLE itab.

  • WHERE doc_type IN ('DKOF01', 'DKCO01').

write : sy-dbcnt.

Former Member
0 Kudos

SELECT * FROM zohdrocm

INTO TABLE itab.

  • WHERE doc_type IN ('DKOF01', 'DKCO01').

write : sy-dbcnt.

Former Member
0 Kudos

Hi

Just use the Function Module 'TABLECOUNT'. Pass the table name and client. You will get the number of records in the Import parameter 'COUNT'.

Thanks

Sharath.