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: 

Count distinct rows from an internal table

0 Kudos

Hi,

i have an internal table containing pairs of entries like

1 1

1 2

1 3

2 1

2 2

What i want to do is to determine the value of rowcount from first column ( here it would be 2 and not 5 ) - to me it seems like a DISTINCT. Any suggestions for that ?

Clemens

1 ACCEPTED SOLUTION

Former Member
0 Kudos

1 . Declare one more itab2.

itab2[] = itab1[].

data : v_lines type i.

delete adjacent duplicates from itab2 comparing field1.

describe table itab2 lines v_lines.

write : V_lines.

5 REPLIES 5

Former Member
0 Kudos

Hi ..

try this code.

<b>delete adjacent duplicates from itab comparing field1.

describe itab lines w_lines.

write w_lines. " w)lines will give u the answer.

</b>

OR

<b>data coubt type i.

LOOP AT itab.

AT NEW <field1>.

count = count + 1.

ENDLOOP.

</b>

Hope it helps you...

Let me know if u have any more doubt...

Reward points if useful......

Suresh.......

Former Member
0 Kudos

Hi clemens,

1. One of the ways is to use COLLECT.

2. suppose your original internal table is ITAB.

Create one more with just one field

STAB eg.

3. Loop at ITAB.

STAB-field1 = ITAB-Field1.

COLLECT stab.

ENDLOOP.

4. In stab u will have only TWO records,

1

2

regards,

amit m.

Former Member
0 Kudos

There are different ways to achieve this:

1. Move the itab contents to a temp itab, then do a SORT and DELETE ADJACENT DUPLICATES...COMPARING <field1>.

2. Use the COLLECT clause. The F1 documentation will tell you more abt this keyword.

3. LOOP AT itab.

AT NEW <field1>.

count = count + 1.

ENDLOOP.

Hope this helps.

Sudha

Former Member
0 Kudos

1 . Declare one more itab2.

itab2[] = itab1[].

data : v_lines type i.

delete adjacent duplicates from itab2 comparing field1.

describe table itab2 lines v_lines.

write : V_lines.

Former Member
0 Kudos

Hi,

Loop at the internal table

& increase a counter at new <field name - col1>

u will get the distinct number of rows