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

Problem fetching data using inner join

Former Member
0 Likes
550

Hi All,

I need to fetch data of a fiedl BSTNK (Customer Purch.order no) from table VBAK using an inner join with table VBAP. Now this INNER JOIN works at times and doesnt at other times.

Can someone explain what is the problem with the same.

CLEAR: g_bstnk.

SELECT SINGLE k~bstnk FROM vbak AS k INNER JOIN vbap AS p

ON kvbeln EQ pvbeln

INTO g_bstnk

WHERE k~auart EQ 'ZC'

AND k~kunnr EQ vbdkl-kunnr

AND k~vkorg EQ vbdkl-vkorg

AND k~guebg LE likp-fkdat

AND k~gueen GE likp-fkdat

AND p~matnr EQ tvbdpl-matnr

AND p~werks EQ tvbdpl-werks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
511

probably you are not hitting the Key fields in Select query which wil result duplicate values. Can you explain abou the values in vbdkl, llikp and tvbdkl. Are you calling this in Loop ?

3 REPLIES 3
Read only

Former Member
0 Likes
512

probably you are not hitting the Key fields in Select query which wil result duplicate values. Can you explain abou the values in vbdkl, llikp and tvbdkl. Are you calling this in Loop ?

Read only

0 Likes
511

Hi Phanendra,

Yes I am using this code within a loop,

Actuallly I manually went to se11 and tried to see whether I get a common data and I could find the

same but when I run the code it doesnt show up the result.

A snapshot of the contents of these fields at run time is as below

vbdkl-kunnr = 0000002411

vbdkl-vkorg = FR01

likp-lfdat = somedate ()

tvbdpl-matnr = 5851097-22

tvbdpl-werks = FR01

Read only

Former Member
0 Likes
511

put vbeln in where condition ..

kvbeln EQ pvbeln

SELECT SINGLE k~bstnk FROM vbak AS k INNER JOIN vbap AS p

ON kvbeln EQ pvbeln

INTO g_bstnk

WHERE k~vbeln = p_vebln (p_vebln or s_vbeln from selection screen)

AND k~auart EQ 'ZC'

AND k~kunnr EQ vbdkl-kunnr

AND k~vkorg EQ vbdkl-vkorg

AND k~guebg LE likp-fkdat

AND k~gueen GE likp-fkdat

AND p~matnr EQ tvbdpl-matnr

AND p~werks EQ tvbdpl-werks.