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: 

inner join

Former Member
0 Kudos

i want to select data from 3 different tables using join.

these tables have a common filed

how an we do it

can u give the syntax

4 REPLIES 4

Former Member
0 Kudos

Hi,

Please try to help yourself first - look at the help at help.sap.com, press the F1 key on your keyboard and finally search SDN before posting. This has been discussed lots of times before.

Gareth.

Former Member
0 Kudos

Hi ,

See below example code for joining three tables. it may give idea about joining three tables.

tables : kna1,

vbak,

vbap.

data : begin of itab occurs 10,

kunnr type kunnr,

name1 type name1,

land1 type land1,

vbeln type vbeln,

erdat type erdat,

netwr type netwr,

posnr type posnr,

matnr type matnr,

kwmeng type kwmeng,

vrkme type vrkme,

end of itab.

select-options : s_kunnr for kna1-kunnr,

s_vbeln for vbak-vbeln.

start-of-selection.

select kkunnr kname1 kland1 vvbeln verdat vnetwr pposnr pmatnr pkwmeng pvrkme

into table itab

from kna1 as k inner join vbak as v

on kkunnr = vkunnr inner join vbap as p

on vvbeln = pvbeln

where k~kunnr in s_kunnr

and v~vbeln in s_vbeln.

*break xverinon02.

if sy-subrc NE 0.

message 'Not found record for given selection' type 'E'.

endif.

top-of-page.

uline.

write:/40 'CUSTOMER SALES ORDER WITH ITEM DETAILS' color 4.

uline.

end-of-page.

uline.

write:/10 'End of Page',60 'Page No.',sy-pagno.

end-of-selection.

sort itab.

loop at itab.

at new kunnr.

write:/ itab-kunnr.

endat.

write:/10 itab-name1, itab-land1, itab-vbeln, itab-erdat, itab-netwr, itab-posnr, itab-matnr, itab-kwmeng, itab-vrkme.

endloop.

Regards,

Vishvesh

if helpful, rewards it.

Former Member
0 Kudos

hi there...

folow the following select query demonstrating inner join on three tables...

SELECT vbakvbeln vbfaerdat INTO (itab-vbeln, itab-wadat)

FROM ( vbak INNER JOIN vbap

ON vbapvbeln = vbakvbeln )

INNER JOIN vbfa ON vbakvbeln = vbfavbelv

WHERE vbak~kunnr = m_wm AND

vbak~vbtyp = 'C' AND

vbfa~erdat IN s_date AND

vbap~matnr = 'MZ1807F' AND

vbfaposnv = vbapposnr AND

vbfa~vbtyp_n = 'J'.

do reward if helpful.

Former Member
0 Kudos

hi,

select t1~f1

t1~f2

t2~f3

t2~f4

t3~f5

t3~f6

into table itab

from <dbtab1> as t1 inner join

<dbtab2> as t2

on t1~<commonfield> = t2`<commonfield>

inner join <dbtab3 > as t3

on t1~<commonfield> = t3<commonfield>

where <conditions>.

hope it helps