Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

finding customers who are having same rating

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

Tags:
replied

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.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question