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

inner join

Former Member
0 Likes
1,339

hi

plse explain how to write inner join

thanks with regards aaryaa

10 REPLIES 10
Read only

Former Member
0 Likes
1,130

Hi Aaryaa,

Please see below example to write inner join.


DATA: DATE   LIKE SFLIGHT-FLDATE, 
      CARRID LIKE SFLIGHT-CARRID, 
      CONNID LIKE SFLIGHT-CONNID. 
 
SELECT F~CARRID F~CONNID F~FLDATE 
    INTO (CARRID, CONNID, DATE) 
    FROM SFLIGHT AS F INNER JOIN SPFLI AS P 
           ON F~CARRID = P~CARRID AND 
              F~CONNID = P~CONNID 
    WHERE P~CITYFROM = 'FRANKFURT' 
      AND P~CITYTO   = 'NEW YORK' 
      AND F~FLDATE BETWEEN '19970910' AND '19970920' 
      AND F~SEATSOCC < F~SEATSMAX. 
  WRITE: / DATE, CARRID, CONNID. 
ENDSELECT.

Selects data from the transparent database tables or views specified in tabref1 and tabref2. tabref1 and tabref2 either have the same form as in variant 1 or are themseleves joine expressions. The key word INNER can be omitted. The database tables or views specified in tabref1 and tabref2 must be recognized in the ABAP/4-Dictionary and declared in the program with an appropriate TABLES statement.

In a relational data structure, it is quite normal for data that belongs together to be split up across several tables to help standardization (see relational database). To regroup this information in a database query, you can link tables using a join command . This formulates conditions for the columns of the tables involved. An inner join contains all combinations of lines from database table tabref1 with lines from database table tabref2 that meet the condition specified in the logical condition ON cond.

Thanks&Regards,

Siri.

Read only

hymavathi_oruganti
Active Contributor
0 Likes
1,130

selecr amatnr bmaktx from mara as A ineer join MAKT

AS B ON AMATNR = BMATNR INTO TABLE ITAB.

Read only

Former Member
0 Likes
1,130

Hi,

did you check the Help on Join's.

if not check it.

The data is to be selected from transparent database tables and/or views determined by tabref1 and tabref2. tabref1 and tabref2 each have the same form as in variant 1 or are themselves Join expressions. The keyword INNER does not have to be specified. The database tables or views determined by tabref1 and tabref2 must be recognized by the ABAP Dictionary.

In a relational data structure, it is quite normal for data that belongs together to be split up across several tables to help the process of standardization (see relational databases). To regroup this information into a database query, you can link tables using the join command. This formulates conditions for the columns in the tables involved. The inner join contains all combinations of lines from the database table determined by tabref1 with lines from the table determined by tabref2, whose values together meet the logical condition (join condition) specified using ON>cond.

Inner join between table 1 and table 2, where column D in both tables in the join condition is set the same:

Table 1 Table 2










A

B

C

D

D

E

F

G

H










a1

b1

c1

1

1

e1

f1

g1

h1

a2

b2

c2

1

3

e2

f2

g2

h2

a3

b3

c3

2

4

e3

f3

g3

h3

a4

b4

c4

3






|--|||--|

\ /

\ /

\ /

\ /

\/

Inner Join

|--||||||||--|

| A | B | C | D | D | E | F | G | H |

|--||||||||--|

| a1 | b1 | c1 | 1 | 1 | e1 | f1 | g1 | h1 |

| a2 | b2 | c2 | 1 | 1 | e1 | f1 | g1 | h1 |

| a4 | b4 | c4 | 3 | 3 | e2 | f2 | g2 | h2 |

|--||||||||--|

DATA: BEGIN OF WA, 
        FLIGHT TYPE SFLIGHT, 
        PFLI   TYPE SPFLI, 
        CARR   TYPE SCARR, 
      END OF WA.

SELECT * INTO WA 
    FROM ( SFLIGHT AS F INNER JOIN SPFLI AS P 
             ON F~CARRID = P~CARRID AND 
                F~CONNID = P~CONNID ) 
           INNER JOIN SCARR AS C 
             ON F~CARRID = C~CARRID 
    WHERE P~CITYFROM = 'FRANKFURT' 
      AND P~CITYTO   = 'NEW YORK' 
      AND F~FLDATE BETWEEN '20010910' AND '20010920' 
      AND F~SEATSOCC < F~SEATSMAX. 
  WRITE: / WA-CARR-CARRNAME, WA-FLIGHT-FLDATE, WA-FLIGHT-CARRID, 
           WA-FLIGHT-CONNID. 
ENDSELECT.

Read only

Former Member
0 Likes
1,130

Hi,

Point to remember is that you can join cluster

tables example cdhdr,cdpos.

Regards

Amole

Read only

Former Member
0 Likes
1,130

Hi,

here is a sample of how to perform multiple table joins..

into an itab.

 
  SELECT VBAP~ERDAT VBAK~VBELN VBAK~VBELN VBAK~VTWEG VBAK~SPART
VBAP~POSNR
 VBAP~MATNR
 LIKP~VBELN LIKP~LFART LIKP~LFDAT LIPS~VGBEL  LIPS~LFIMG FROM ( ( ( VBAK
 INNER JOIN VBAP ON  VBAP~VBELN = VBAK~VBELN ) INNER JOIN LIPS ON
LIPS~VGBEL = VBAP~VBELN ) INNER JOIN LIKP ON LIKP~VBELN = LIPS~VBELN )
INTO TABLE I_LIKPLINK WHERE VBAK~VBELN IN S_VBEL AND LIPS~VGPOS =
VBAP~POSNR.
  ULINE.



  endform.

Read only

Former Member
0 Likes
1,130

Hi Aaryaa,

Mainly you need to concentrate on the key fields while using Join conditions. If you do not find data in any of your joined tables you will not be able to fetch that particular record.

Here is the sample code for shipment details.

select vttptknum vttptpnum vttpvbeln vepoposnr

vepovenum vepovepos vekpexidv vepovemng vbfa~vbelv

vbfaposnv vbapmatnr vttktdlnr vttkroute

vttkerdat vttkexti1

into table i_shipment

from vttp

inner join vttk

on vttktknum = vttptknum

inner join vepo

on vepovbeln = vttpvbeln

inner join vekp

on vekpvenum = vepovenum

inner join vbfa

on vbfavbeln = vepovbeln

and vbfaposnn = vepoposnr

inner join vbap

on vbapvbeln = vbfavbelv

and vbapposnr = vbfaposnv

where vttp~tknum = v_shipment.

Regards,

Sudheer

Read only

Former Member
0 Likes
1,130

Hi,

Small correction to my earlier mail.

Inner join is not possible on cluster table.

Regards

Amole

Read only

0 Likes
1,130

Example :

Join the columns carrname, connid, fldate of the database tables scarr, spfli and sflight by means of two inner joins. A list is created of the flights from p_cityfr to p_cityto. Alternative names are used for every table.

PARAMETERS: p_cityfr TYPE spfli-cityfrom,

p_cityto TYPE spfli-cityto.

DATA: BEGIN OF wa,

fldate TYPE sflight-fldate,

carrname TYPE scarr-carrname,

connid TYPE spfli-connid,

END OF wa.

DATA itab LIKE SORTED TABLE OF wa

WITH UNIQUE KEY fldate carrname connid.

SELECT ccarrname pconnid f~fldate

INTO CORRESPONDING FIELDS OF TABLE itab

FROM ( ( scarr AS c

INNER JOIN spfli AS p ON pcarrid = ccarrid

AND p~cityfrom = p_cityfr

AND p~cityto = p_cityto )

INNER JOIN sflight AS f ON fcarrid = pcarrid

AND fconnid = pconnid ).

LOOP AT itab INTO wa.

WRITE: / wa-fldate, wa-carrname, wa-connid.

ENDLOOP.

Read only

Former Member
0 Likes
1,130

HI Madhu

The data that can be selected with a view depends primarily on whether the view implements an inner join or an outer join. With an inner join, you only get the records of the cross-product for which there is an entry in all tables used in the view. With an outer join, records are also selected for which there is no entry in some of the tables used in the view.

The set of hits determined by an inner join can therefore be a subset of the hits determined with an outer join.

Database views implement an inner join. The database therefore only provides those records for which there is an entry in all the tables used in the view. Help views and maintenance views, however, implement an outer join.

Chk out this link......for further detials....

http://help.sap.com/saphelp_erp2005/helpdata/en/cf/21ec77446011d189700000e8322d00/content.htm

Cheers:-)

Mithlesh

Read only

Former Member
0 Likes
1,130

Hi,

Proper use of Inner Join:

=========================

When multiple SAP tables are logically joined, it is always advisable to use inner join to read the data from them. This certainly reduces the load on the network.

Let us take an example of 2 tables, zairln and zflight. The table zairln has the field airln, which is the airline code and the field lnnam, which is the name of the airline. The table zflight has the field airln, the airline code and other fields which hold the details of the flights that an airline operates.

Since these 2 tables a re logically joined by the airln field, it is advisable to use the inner join.

Select aairln alnnam bfligh bcntry

into table int_airdet

From zairln as a inner join zflight as b on

aairln = bairln.

In order to restrict the data as per the selection criteria, a where clause can be added to the above inner join.

I hope this info is suffice.

Regs,

Venkat Ramanan