09-19-2008 2:48 PM
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
09-19-2008 3:18 PM
Hi There,
try this
SELECT COUNT( DISTINCT CARRID )
INTO COUNT
FROM SPFLI
WHERE
CITYTO = 'NEW YORK'.
WRITE: / COUNT.
Hope this helps
Thanks
09-19-2008 3:22 PM
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
09-19-2008 3:24 PM
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
09-19-2008 3:31 PM
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