Application Development and Automation 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: 
Read only

Left Outer Join - Mismatch in Result

Former Member
0 Likes
948

Hi,

I'm trying to get details of the Customers who are not having sales document using standard tables KNA1 and VBAK to display records.

Inner join displays 236 records and Left-outer join returns 241 records, that means 5 Customers are there without sales document.

If I use the following code :

SELECT KNA1~KUNNR KNA1~LAND1 KNA1~NAME1 VBAK~VBELN VBAK~ERDAT VBAK~NETWR
INTO TABLE ITAB
FROM KNA1 LEFT OUTER JOIN VBAK
ON KNA1~KUNNR = VBAK~KUNNR
WHERE KNA1~KUNNR IN CUST
ORDER BY KNA1~KUNNR.


LOOP AT ITAB WHERE VBELN IS INITIAL.

Where Cust is a select-option to take input Customer Number Low and High value. This code returns the correct value i.e 5.

Whereas if I use

SELECT KNA1~KUNNR KNA1~LAND1 KNA1~NAME1 VBAK~VBELN VBAK~ERDAT VBAK~NETWR
INTO TABLE ITAB
FROM KNA1 LEFT OUTER JOIN VBAK
ON KNA1~KUNNR = VBAK~KUNNR AND VBAK~VBELN EQ 0
WHERE KNA1~KUNNR IN CUST
ORDER BY KNA1~KUNNR.


LOOP AT ITAB.

displays 8 records.

What I'm trying to do is, the Select statement only to fetch the number of records based on the condition where there is no sales document for the particular customer rather then getting all the records into internal table and then looping at no sales document.

Thanks in advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
892

As Rob suggests, use a subquery

Read KNA1, subquery VAKPA for KNA1-KUNNR and correct PARVW value...If found, proceed with next KNA1, if not found, write the KNA1 data to an internal table.

See SE30 tips and tricks for how to do a subquery.

Hi,

I'm trying to get details of the Customers who are not having sales document using standard tables KNA1 and VBAK to display records.

Inner join displays 236 records and Left-outer join returns 241 records, that means 5 Customers are there without sales document.

If I use the following code :

SELECT KNA1~KUNNR KNA1~LAND1 KNA1~NAME1 VBAK~VBELN VBAK~ERDAT VBAK~NETWR
INTO TABLE ITAB
FROM KNA1 LEFT OUTER JOIN VBAK
ON KNA1~KUNNR = VBAK~KUNNR
WHERE KNA1~KUNNR IN CUST
ORDER BY KNA1~KUNNR.


LOOP AT ITAB WHERE VBELN IS INITIAL.

Where Cust is a select-option to take input Customer Number Low and High value. This code returns the correct value i.e 5.

Whereas if I use

SELECT KNA1~KUNNR KNA1~LAND1 KNA1~NAME1 VBAK~VBELN VBAK~ERDAT VBAK~NETWR
INTO TABLE ITAB
FROM KNA1 LEFT OUTER JOIN VBAK
ON KNA1~KUNNR = VBAK~KUNNR AND VBAK~VBELN EQ 0
WHERE KNA1~KUNNR IN CUST
ORDER BY KNA1~KUNNR.


LOOP AT ITAB.

displays 8 records.

What I'm trying to do is, the Select statement only to fetch the number of records based on the condition where there is no sales document for the particular customer rather then getting all the records into internal table and then looping at no sales document.

Thanks in advance.

5 REPLIES 5
Read only

Former Member
0 Likes
892

Moderator message - Welcome to SCN. You might try a sub-query rather than a JOIN here. Rob

Read only

Former Member
0 Likes
893

As Rob suggests, use a subquery

Read KNA1, subquery VAKPA for KNA1-KUNNR and correct PARVW value...If found, proceed with next KNA1, if not found, write the KNA1 data to an internal table.

See SE30 tips and tricks for how to do a subquery.

Read only

0 Likes
892

Thanks Rob and Breakpoint, but I would like to know why would JOIN query will not work.

Read only

0 Likes
892

inner join - retain where table-field values are equal...

left outer join - retain all of left whether or not matched on the right...

Read only

0 Likes
892

Yeah that should be the reason, so even though I wanted to restrict the number of records without sales doc through select query, Left outer join wouldn't work.

Thanks BreakPoint.