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 lines in table

Former Member
0 Likes
4,212

hallow

i have internal table and i wont to count lines with key

example

data

001

001

002

003

001

i wont in some fiels to now how much number of 001 i have here 3

regards

1 ACCEPTED SOLUTION
Read only

former_member150733
Contributor
0 Likes
3,189

syntax:

DESCRIBE TABLE itab2 LINES n.

You will get teh number of lines in variable n.

If you want to know the number of keys proceed this way.

1. Get all the keys to a itab1.

2. GEt all the data to itab2

3. Loop at itab1.

loop at itab2 where key = itab1-key.

  • count the number of times the key ocuurs and store * to a variable or do a write

endloop.

endloop.

Hi,

You can get the number of lines in a table using the DESCRIBE statement.

DESCRIBE TABLE itab [KIND knd] [LINES lin] [OCCURS n]

Effect

This statement determines some properties of the internal table itab and assigns them to the specified variables. The various additions enable you to determine the table type, the number of currently filled rows and the initial memory requirement.

In addition, the system fields sy-tfill and sy-tleng are filled with the current number of table rows and the length of a table row in bytes.

You can also loop at the internal table where data = key.Then keep an count and increase it everytime.

loop at itab where data = key.

cnt = cnt + 1.

endloop.

This will serve your purpose I suppose.

Hope it will be useful.

Thanks,

Sandeep.

5 REPLIES 5
Read only

former_member150733
Contributor
0 Likes
3,190

syntax:

DESCRIBE TABLE itab2 LINES n.

You will get teh number of lines in variable n.

If you want to know the number of keys proceed this way.

1. Get all the keys to a itab1.

2. GEt all the data to itab2

3. Loop at itab1.

loop at itab2 where key = itab1-key.

  • count the number of times the key ocuurs and store * to a variable or do a write

endloop.

endloop.

Read only

Former Member
0 Likes
3,189

hi,

data: value type i.

loop at itab where itab-fld = '001'.

value = value + 1.

write:/10 value.

endloop.

and if u want to count no. of lines ina internal table then use describe command as

ex: describe lines value.

write:/10 value.

if useful reward some points.

with regards,

suresh.

Read only

Former Member
0 Likes
3,189

data: lv_count typei.

loop at itab into wa.

if itab-some_field = 'value'.

lv_count = lv_count + 1.

endif.

endloop.

write lv_count

Read only

Former Member
0 Likes
3,189

Hi,

You can get the number of lines in a table using the DESCRIBE statement.

DESCRIBE TABLE itab [KIND knd] [LINES lin] [OCCURS n]

Effect

This statement determines some properties of the internal table itab and assigns them to the specified variables. The various additions enable you to determine the table type, the number of currently filled rows and the initial memory requirement.

In addition, the system fields sy-tfill and sy-tleng are filled with the current number of table rows and the length of a table row in bytes.

You can also loop at the internal table where data = key.Then keep an count and increase it everytime.

loop at itab where data = key.

cnt = cnt + 1.

endloop.

This will serve your purpose I suppose.

Hope it will be useful.

Thanks,

Sandeep.

Read only

PS_1978
Active Participant
0 Likes
3,189

Hi Shnya,

first sort the internal table based on the field that u want to have count...

Example: lets suppose that the field name itself is data and the internal table name is l_itab and it has the values that u have given in your post...

Sample code:

sort l_itab by data.

loop at l_itab into wa_itab.

lv_counter = lv_counter + 1.

at end of data.

  • Each time it triggers, lv_counter will be having the * value for a particular value in data field.. for the * first time it will be having counter for 001, second * time 002 and so on...

  • write code according to your requirement.. and then * clear lv_counter...

endat.

endloop.

Hope this helps u...

Regards,

Phani.