How to count how many records does one Itab have???

Question: How to count how many records does one Itab have???
Thanks!!!



Answer:
data cpt_lines type i.
describe table itab lines cpt_lines.

Answer:
thanks everybody!

why i wrote this...it doesnt work??

BEGIN OF ITAB.
COUNT TYPE I,
END OF ITAB.
...

SELECT ...FROM ... INTO ITAB.
ENDSELECT.

LOOP AT ITAB.
ITAB-COUNT = ITAB-COUNT + 1.
MODIFY ITAB.
ENDLOOP.

WRITE: ITAB-COUNT.


---------
but the output is :
1
1
1
1
1
1
1...

what i want is:
1
2
3
4
5
6
...


how to do??? thankx!!

Answer:
You're looping through an itab. You're adding 1 to the ITAB-COUNT field. This field initially will be empty on each new record. So, of course you will get 1 on each line.

As mentioned, using DESCRIBE is much easier and would actually work.

Answer:
You're looping through an itab. You're adding 1 to the ITAB-COUNT field. This field initially will be empty on each new record. So, of course you will get 1 on each line.

As mentioned, using DESCRIBE is much easier and would actually work.

Wow!! Thanks Really!! u made me know more.

DESCRIBE is really a simplist way and it is very well to work.

but now i want to create an Item No which is begin from 1 with increment of 1.

sth like what i have posted above.

Does any people tell me how to realize it???

thanks again!!

Answer:
data: l_count type i.

clear l_count.

loop at itab.
  itab-count = l_count + 1.
  modify itab.
endloop.

Ain't it basic for other languages as well?

data: l_count type i.

clear l_count.

loop at itab.
  itab-count = l_count + 1.
  modify itab.
  l_count = l_count + 1
endloop.

that's better.

Answer:
Well, I got confused by wiraone's post so I don't know how it may have affected the original poster.

SY-TABIX does provide the line number the OP seems to want, and I suggest he / she reads up on it, but this would do it as well.

DATA: w_count TYPE I.

LOOP AT  itab INTO wa_itab.
   w_count = w_count + 1.
   wa_itab-count =  w_count.
   MODIFY i_count FROM wa_count.
ENDLOOP.

ie use a separate variable, which is never cleared, to hold your line count.

Answer:
Haa.. haa.. there you goes when trying to show off!! Apology to the OP My bad ..

What I want to do really was:

LOOP AT  itab.
   itab-count =  l_count = l_count + 1.
   MODIFY itab.
ENDLOOP.

(Trying to cover myself indeed!!! ) ..
Copyright ?2007 - 2008 www.jt77.com