‎2007 Jan 22 8:25 AM
Hi,
is it possible to perform sql-command on internal table as below
shown. If not, which alternatives are given.
SELECT COUNT( DISTINCT kunnr ) from itab into table itab2
I have the following situation:
Internal table "itab" contains many datas with various custumers. I want
to collect the unique customernumber in another internal table e.x itab2.
Regards
Ilhan
‎2007 Jan 22 8:29 AM
Hi Ilhan,
You cannot perform SQL commands on internal tables.
To get the unique customers from an internal table like this:
DATA itab2 LIKE TABLE OF itab.
DATA v_cus TYPE i.
itab2[] = itab[].
SORT itab2 BY kunnr.
DELETE ADJACENT DUPLICATES FROM itab2 COMPARING kunnr.
"itab2 will have unique customers
DESCRIBE TABLE itab2 LINES v_cus.
"v_cus will have the count of unique customers.
Regards
Wenceslaus
‎2007 Jan 22 8:26 AM
hi,
<b>No you cannot use those statements for internal table as SQL Commands are for database tables only ..</b>
Regards,
Santosh
‎2007 Jan 22 8:27 AM
No it will not work. SELECT statement will not work on internal tables. It can be used only on database tables and views.
If you want to SUM an internal table field, you will have to loop the table and then sum it up manually.
Manoj
‎2007 Jan 22 8:28 AM
it should work....
if not write this way...
SELECT DISTINCT kunnr from <database> into table itab2.
describe table itab2 lines v_lines.....
‎2007 Jan 22 8:29 AM
Hi Ilhan,
You cannot perform SQL commands on internal tables.
To get the unique customers from an internal table like this:
DATA itab2 LIKE TABLE OF itab.
DATA v_cus TYPE i.
itab2[] = itab[].
SORT itab2 BY kunnr.
DELETE ADJACENT DUPLICATES FROM itab2 COMPARING kunnr.
"itab2 will have unique customers
DESCRIBE TABLE itab2 LINES v_cus.
"v_cus will have the count of unique customers.
Regards
Wenceslaus
‎2007 Jan 22 8:31 AM
Hi,
no, you must do sth like this:
loop at itab into itab2.
collect itab2.
endloop.
describe table itab2 lines sy-tfill.A.