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

regarding inner join

Former Member
0 Likes
455

hey!!

can anybody tell me how to use iner join with select statement with common fields in the two and other common fields with another two tables.Give an suitable example.

regards,

3 REPLIES 3
Read only

Former Member
0 Likes
433

See example:

DATA: DATE LIKE SFLIGHT-FLDATE,

CARRID LIKE SFLIGHT-CARRID,

CONNID LIKE SFLIGHT-CONNID.

SELECT FCARRID FCONNID F~FLDATE

INTO (CARRID, CONNID, DATE)

FROM SFLIGHT AS F INNER JOIN SPFLI AS P

ON FCARRID = PCARRID

WHERE FCONNID = PCONNID

AND P~CITYFROM = 'FRANKFURT'

AND P~CITYTO = 'NEW YORK'

AND F~FLDATE BETWEEN '20010910' AND '20010920'

AND FSEATSOCC < FSEATSMAX.

WRITE: / DATE, CARRID, CONNID.

ENDSELECT.

Regards

Read only

former_member386202
Active Contributor
0 Likes
433

Hi,

Refer this code for inner join

*--Select query to pick the Billing document Billing date Billing

  • category Billing type Distribution channel Number of doc condition

  • Billing item Material Number Plant Referance Subtotal 2 Cost in

  • document currency and Partner function from table VBRK VBRP and VBPA

  • using inner join

SELECT a~vbeln "Billing document

a~fkdat "Billing date

a~fktyp "Billing category

a~fkart "Billing type

a~vtweg "Distribution channel

a~knumv "Number of doc condition

b~posnr "Billing item

b~matnr "Material Number

b~werks "Plant

b~vgbel "Referance

b~kzwi2 "Subtotal 2

b~wavwr "Cost in document currency

c~kunnr "Partner function

FROM vbrk AS a

INNER JOIN vbrp AS b

ON avbeln EQ bvbeln

INNER JOIN vbpa AS c

ON bvbeln EQ cvbeln

INTO CORRESPONDING FIELDS OF TABLE it_vbrp

WHERE fkdat IN s_erdat

AND parvw EQ 'ZS'.

IF sy-subrc EQ 0.

*--Sort table by Referance

SORT it_vbrp BY vgbel1.

ENDIF.

but it reduces the performance so better to use FOR ALL ENTRIES

*--Select query to pick the Delivery Material Number Plant

  • Movement type Subtotal 2 and Quantity from table LIPS

SELECT vbeln "Delivery

matnr "Material Number

werks "Plant

bwart "Movement type

kzwi2 "Subtotal 2

lfimg "Quantity

FROM lips

INTO CORRESPONDING FIELDS OF TABLE it_lips

FOR ALL ENTRIES IN it_vbrp

WHERE vbeln EQ it_vbrp-vgbel1.

IF sy-subrc EQ 0.

*--Sort table by Delivery

SORT it_lips BY vbeln.

ENDIF.

Regards,

Prashant

Read only

Former Member
0 Likes
433

refer following querry for inner join on more than two tables...

select a~bukrs

a~anln1

a~anln2

a~anlkl

a~txt50

a~ord41

a~ord42

a~ord43

b~afabe

b~ndabj

b~ndabp

b~kansw

b~knafa

b~kaafa

b~nafag

b~nafap

b~aafam

b~aafag

c~kostl

d~afasl

d~ndjar

d~ndper

into corresponding fields of table gt_master

from ( ( anla as a inner join anlc as b

on abukrs = bbukrs

and aanln1 = banln1

and aanln2 = banln2 )

inner join anlz as c

on abukrs = cbukrs

and aanln1 = canln1

and aanln2 = canln2 )

inner join anlb as d

on abukrs = dbukrs

and aanln1 = danln1

and aanln2 = danln2

where a~bukrs in s_comp

and a~anlkl in s_astcls.