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: 

finding customers who are having same rating

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.

4 REPLIES 4

Former Member
0 Kudos

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

0 Kudos

HI,

NO still it is giving same result. I have tried all your options.

Former Member
0 Kudos

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 Kudos

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.