10-14-2008 11:39 AM
Hi all,
The below is my Z table. I want to findout the Customer names who are having the same rating.
TABLE CUST
CNUM CNAME CITY RATING SNUM
2001 Hoffman London 100 1001
2002 Giovanne Rome 200 1003
2003 Liu San Jose 300 1002
2004 Grass Brelin 100 1002
2006 Clemens London 300 1007
2007 Pereira Rome 100 1004
and i have written the code.
TYPES: BEGIN OF t_final,
cname TYPE zcust-cname,
c1name TYPE zcust-cname,
rating TYPE zcust-rating,
END OF t_final.
DATA: itab_final TYPE TABLE OF t_final,
wa_final TYPE t_final.
SELECT acname bcname a~rating INTO TABLE itab_final
FROM zcust as a inner join zcust as b
on arating = brating and
acnum <> bcnum and
acname <> bcname.
LOOP AT itab_final INTO wa_final .
WRITE:/ wa_final-cname,wa_final-c1name, wa_final-rating.
ENDLOOP.
This is giving the following output:
GRASS HOFFMAN 0100
PEREIRA HOFFMAN 0100
CLEMENS LIU 0300
HOFFMAN GRASS 0100
PEREIRA GRASS 0100
LIU CLEMENS 0300
HOFFMAN PEREIRA 0100
GRASS PEREIRA 0100
But this is having duplication. right. How to delete those rows ?
Thanks in advance
krupali
10-14-2008 11:59 AM
Basically this is not the right way to use inner join condition,
Try to modify your code as follows:
TYPES: BEGIN OF t_final,
cname TYPE zcust-cname,
c1name TYPE zcust-cname,
rating TYPE zcust-rating,
END OF t_final.
DATA: itab_final TYPE TABLE OF t_final,
wa_final TYPE t_final.
SELECT cname c1name rating INTO TABLE itab_final
FROM zcust.
sort itab_final by rating.
LOOP AT itab_final into wa_final.
WRITE:/ wa_final-cname,wa_final-c1name, wa_final-rating.
ENDLOOP.
10-14-2008 11:45 AM
Hi,
Sort the itab by cnum. " or cname
delete adjacent duplicates from <itab> comparing cnum. "or cname
Thanks & Regards,
Navneeth K.
Edited by: Navneeth Bothra on Oct 14, 2008 12:45 PM
10-14-2008 11:58 AM
HI,
NO still it is giving same result. I have tried all your options.
10-14-2008 11:59 AM
Basically this is not the right way to use inner join condition,
Try to modify your code as follows:
TYPES: BEGIN OF t_final,
cname TYPE zcust-cname,
c1name TYPE zcust-cname,
rating TYPE zcust-rating,
END OF t_final.
DATA: itab_final TYPE TABLE OF t_final,
wa_final TYPE t_final.
SELECT cname c1name rating INTO TABLE itab_final
FROM zcust.
sort itab_final by rating.
LOOP AT itab_final into wa_final.
WRITE:/ wa_final-cname,wa_final-c1name, wa_final-rating.
ENDLOOP.
10-14-2008 12:06 PM
HI navneeth,
Your code will display all the customer names and their rating.
but my requirement is to display the customers who are having same Rating.
any other idea.