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: 

Retrieve the number of different occurencies in a row

Former Member
0 Kudos

Hi experts,

Here is my problem : I have a sorted itab that looks like with vendor number that looks like that:

0000009562

0000009562

0000009562

0000009563

0000009563

0000009563

0000009563

0000009564

0000009564

I would like to retrieve the number of distinct ocurrances meaning 3.

I tried to use the SELECT COUNT dinstinct instruction but can't find the proper syntax.

Anybody can help ?

<removed_by_moderator>

Many thanks.

C.K.

Edited by: Julius Bussche on Sep 19, 2008 4:27 PM

4 REPLIES 4

Former Member
0 Kudos

Hi There,

try this

SELECT COUNT( DISTINCT CARRID )

INTO COUNT

FROM SPFLI

WHERE

CITYTO = 'NEW YORK'.

WRITE: / COUNT.

Hope this helps

Thanks

naimesh_patel
Active Contributor
0 Kudos

If your data is already in th internal table you can use the COLLECT to get the distinct number of the document number.

Like:


TYPES: BEGIN OF TY_DIST,
       BELNR TYPE BELNR,
       COUNT TYPE I,
       END   OF TY_DIST.
       
DATA: T_DIST TYPE STANDRAD TABLE OF TY_DIST,
      WA_DIST TYPE TY_DIST.
      
LOOP AT ITAB.
  WA_DIST-BELNR = ITAB-BELNR.
  WA_DIST-COUNT = 1.   "<< MUST BE 1 ALWAYS
  COLLECT WA_DIST TO T_DIST.
  CLEAR   WA_DIST.
ENDLOOP.  

* Table T_DIST will have the distinct count of the document

Regards,

Naimesh Patel

JozsefSzikszai
Active Contributor
0 Kudos

hi,

if I understand right this is an internal table. This meand that SELECT COUNT( * ) won't work, because that is used for database tables.

One thing you can do (there could be other solutions as well):

DATA : lv_count TYPE i.
SORT itab BY lifnr.
LOOP AT itab.
AT NEW lifnr.
count = count + 1.
ENDAT.
ENDLOOP.

Now lv_count contains the number of different vendor numbers.

hope this helps

ec

former_member212653
Active Contributor
0 Kudos

try this:


"Declare another int tab of type original int tab

ITAB_DUMMY[] = ITAB[].

delete adjacent duplicates from itab_dummy comparing f1.
" delete by comparing with the field which you want distinct records
data: lines type i.
lines  = LINES( itab_dummy).
"now lines will have the distinct no of records