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 unique data records from internal table

Former Member
0 Likes
1,992

Hi ,

I want to select unique enteries from an internal table and count that numebr in another row

For example my internal table

ITAB

EBELN

0026000060

0026000060

0026000060

0026000060

0026000061

0026000061

0026000061

0026000062

0026000062

0026000063

I need to show in ITAB_FINAL

 EBELN                                              COUNT OF UNIQUE RECORDS
0026000060                                                    4
0026000060                                                    4
0026000060                                                    4
0026000060                                                    4
0026000061                                                     3
0026000061                                                     3
0026000061                                                      3
0026000062                                                        2
0026000062                                                           2
0026000063                                                           1

Please help me how to achive this.

Thanks

Kiran

Hi ,

I want to select unique enteries from an internal table and count that numebr in another row

For example my internal table

ITAB

EBELN

0026000060

0026000060

0026000060

0026000060

0026000061

0026000061

0026000061

0026000062

0026000062

0026000063

I need to show in ITAB_FINAL

 EBELN                                              COUNT OF UNIQUE RECORDS
0026000060                                                    4
0026000060                                                    4
0026000060                                                    4
0026000060                                                    4
0026000061                                                     3
0026000061                                                     3
0026000061                                                      3
0026000062                                                        2
0026000062                                                           2
0026000063                                                           1

Please help me how to achive this.

Thanks

Kiran

2 REPLIES 2
Read only

Kiran_Valluru
Active Contributor
0 Likes
985

Hi kiran.,

refer this.,

types:begin of ty_ebeln,
  ebeln type ebeln,
  end of ty_ebeln.

types:begin of ty_count,   " req op structure..
  ebeln type ebeln,
  count type i,
  end of ty_count.

data:itab type table of ty_ebeln,
      wa_ebeln type ty_ebeln,
      it_count type table of ty_count,
      wa_count type ty_count.

data index type i.

sort itab by ebeln ascending.

LOOP AT itab into wa_ebeln.
  index = index + 1.

  at end of ebeln.
    wa_count-ebeln = wa_ebeln-ebeln.
    wa_count-count = index.
    append wa_count to it_count.
    clear wa_count.
    index = 0.
  endat.


ENDLOOP.


LOOP AT it_count into wa_count.

  write:/ wa_count-ebeln, 10 wa_count-count.

ENDLOOP.

reply if u need some more clarifications,.

Thanks & Regards

Kiran

Read only

Former Member
0 Likes
985

Hi,

I have solved my own.

..CLEAR g_ebeln.

loop at itab into wa.

IF wa-ebeln NE g_Ebeln.
 LOOP AT itab where ebeln = wa-ebeln.
   g_count = g_count + 1.
 ENDLOOP.
ENDIF. 
g_ebeln = wa-ebeln.
 
 clear wa_final.
 wa_final-ebeln = wa-ebeln.
 wa_final-count = g_count.
 append wa_final to itab_final.

ENDLOOP.  

Thanks..