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

A Loop count

Former Member
0 Likes
5,616

How to do a loop for a table to get the total count of the rows?

And write out the total number of rows.

14 REPLIES 14
Read only

Former Member
0 Likes
2,689

Hi

i am sending you a smaple code from my program

plz see this you can understand very easyly

LV_COUNT = 0.

LOOP AT IT_OUTPUT INTO WA_OUTPUT.

LV_COUNT = LV_COUNT + 1.

WA_OUTPUT-COUNT = LV_COUNT.

APPEND WA_OUTPUT TO IT_OUTPUT_1.

ENDLOOP.

REFRESH IT_OUTPUT.

IT_OUTPUT = IT_OUTPUT_1.

output is my final internal table and output1 is also type of that output structure

<b>Reward if usefull</b>

Read only

former_member188827
Active Contributor
0 Likes
2,689

loop at itab.

write:/sy-tabix.

endloop.

Message was edited by:

abapuser

Read only

0 Likes
2,689

HI

Check the thread

Sail

Read only

Former Member
0 Likes
2,689

Hi ,

If i understand correctly you want to get the number of rows in an internal table ,

if that is the case use the DESCRIBE command.

with the addition LINES.

Regards

Arun

Read only

Former Member
0 Likes
2,689

DATA : MY_TABIX TYPE SY-TABIX.

LOOP AT ITAB.

AT LAST .

MY-TABIX = SY-TABIX.

ENDAT.

ENDLOOP.

IN MY_TABIX YOU HAVE NUMBER OF RECORDS.

REWARD IF USEFUL

AMIT SINGLA

Read only

0 Likes
2,689

describe table itab.

now it wil fil the system field SY-TFILL wid number of lines in internal table

use like this

describe table itab.

write : sy-tfill.

reward if useful

Read only

Former Member
0 Likes
2,689

Instead of looping into the table you can use a direct ABAP command:

DESCRIBE TABLE itab LINES gv_record.

WRITE: gv_lines.

gv_line should be type 'i' and will give you number of records in an internal table.

PS: Please mark this question answered since this solves your query.

Regards.

Read only

Former Member
0 Likes
2,689

I'm looping my database table. I want to know how many records i have in my database table.

Read only

0 Likes
2,689

How can you loop at your DB table thats not intelligent.

You can transfer them into an internal table and find the entry count.

Read only

0 Likes
2,689

use sy-dbcnt for the number of record fetched from database table

Read only

Former Member
0 Likes
2,689

I'm looping my database table not internal table.

Read only

0 Likes
2,689

den use

syst-dbcnt

Read only

0 Likes
2,689

your need to select records which you want from your table into an internal table and then you can loop it and count the number of records.

hope this would be help ful.

cheers

AJ

Read only

Former Member
0 Likes
2,689

Thanks everybody. My question is solved.

I just use SQL statement to loop my table. 😃