Skip to Content
0
Former Member
Jun 19, 2015 at 07:46 AM

Inner Join(Giving duplicate entries) - SAP HANA AMDP

544 Views

The below query is giving duplicate entry when INNER JOIN used with CEPCT , where there exist only 1 entry against profit-center.

et_actual =

SELECT r.prctr AS prctr, r.racct AS racct, r.actual AS actual, r.plan AS plan, s.ltext AS ltext, r.segment AS segment

FROM (

SELECT prctr AS prctr, racct AS racct,

SUM( ( CASE when iv_rpamxl <= 1 AND iv_rpmaxh >= 1 THEN hsl01 ELSE 0 end ) +

( CASE when iv_rpamxl <= 2 AND iv_rpmaxh >= 2 THEN hsl02 ELSE 0 end ) +

( CASE when iv_rpamxl <= 3 AND iv_rpmaxh >= 3 THEN hsl03 ELSE 0 end ) +

( CASE when iv_rpamxl <= 4 AND iv_rpmaxh >= 4 THEN hsl04 ELSE 0 end ) +

( CASE when iv_rpamxl <= 5 AND iv_rpmaxh >= 5 THEN hsl05 ELSE 0 end ) +

( CASE when iv_rpamxl <= 6 AND iv_rpmaxh >= 6 THEN hsl06 ELSE 0 end ) +

( CASE when iv_rpamxl <= 7 AND iv_rpmaxh >= 7 THEN hsl07 ELSE 0 end ) +

( CASE when iv_rpamxl <= 8 AND iv_rpmaxh >= 8 THEN hsl08 ELSE 0 end ) +

( CASE when iv_rpamxl <= 9 AND iv_rpmaxh >= 9 THEN hsl09 ELSE 0 end ) +

( CASE when iv_rpamxl <= 10 AND iv_rpmaxh >= 10 THEN hsl10 ELSE 0 end ) +

( CASE when iv_rpamxl <= 11 AND iv_rpmaxh >= 11 THEN hsl11 ELSE 0 end ) +

( CASE when iv_rpamxl <= 12 AND iv_rpmaxh >= 12 THEN hsl12 ELSE 0 end ) +

( CASE when iv_rpamxl <= 13 AND iv_rpmaxh >= 13 THEN hsl13 ELSE 0 end ) +

( CASE when iv_rpamxl <= 14 AND iv_rpmaxh >= 14 THEN hsl14 ELSE 0 end ) +

( CASE when iv_rpamxl <= 15 AND iv_rpmaxh >= 15 THEN hsl15 ELSE 0 end ) +

( CASE when iv_rpamxl <= 16 AND iv_rpmaxh >= 16 THEN hsl16 ELSE 0 end ) ) AS actual,

0 AS plan,

segment AS segment

FROM faglflext

WHERE ryear = iv_ryear

AND rldnr = iv_rldnr

AND rrcty = '0'

AND rvers = '001'

AND rbukrs = 'IN10'

AND racct = '0052550001'

AND prctr = 'IN1010106F'

AND kokrs = iv_kokrs

GROUP BY prctr, racct, segment

) AS r

INNER JOIN cepct AS s

ON r.prctr = s.prctr

WHERE s.spras = iv_langu

AND s.kokrs = iv_kokrs

ORDER BY r.prctr, r.racct DESC ;