Skip to Content
0
Jun 23 at 09:08 AM

SQL use Subquery

93 Views Last edit Jun 23 at 09:40 AM 2 rev

Hello,

I try to write a SQL in my ABAP Report but it does not work with subqueries.

I do not know how to change the SQL to fix my problem.

SELECT DISTINCT m~CONTR_NUM,
m~CONTR_NUM_P,
s~SUBSCRIPTION_ID,
h~CONTRACT_TYPE,
h~CUSTOMER,
m~PRODUCT_OFFERING,
p1~MAKTX,
k~PRODUCT_OFFERING,
p2~MAKTX
FROM ( SELECT v~PRODINST_ID, v~CONTR_NUM, p~CONTR_NUM_P, p~PRODUCT_OFFERING
FROM YGK_CONT_P as p
JOIN YGK_CONT_RELA_V as v
ON p~PRODINST_ID = v~PRODINST_ID
AND p~contr_num = v~contr_num
WHERE v~RELATION_NAME = 'has_Zweitanbindung'
AND p~ITEM_STATUS = 'A' ) as m
inner join (SELECT v~PRODINST_ID,
v~CONTR_NUM,
p~CONTR_NUM_P,
p~PRODUCT_OFFERING
FROM YGK_CONT_P as p
JOIN YGK_CONT_RELA_V as v
ON p~PRODINST_ID = v~PRODINST_ID
AND p~contr_num = v~contr_num
WHERE v~RELATION_NAME = 'has_Erstanbindung'
AND p~ITEM_STATUS = 'A') as k
ON m~contr_num = k~contr_num
Inner join MAKT as p1
ON ( p1~MATNR = m~PRODUCT_OFFERING AND p1~SPRAS = 'D' )
Inner join MAKT as p2
ON ( p2~MATNR = k~PRODUCT_OFFERING AND p2~SPRAS = 'D' )
INNER JOIN YGK_CONT_H as h
ON m~contr_num = h~contr_num
INNER JOIN YGK_CONT_P as s
ON ( m~contr_num = s~contr_num AND s~PARENT_ID = ' ' AND
s~item_status = 'A' )
WHERE ( m~CONTR_NUM, m~CONTR_NUM_P ) NOT IN
( SELECT e~CONTR_NUM, e~CONTR_NUM_P
FROM YGK_CONT_RELA_V as e
WHERE e~RELATION_NAME = 'has_ProaktivesServicemanagement' ).