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

select or inner join

Former Member
0 Likes
715

hi all,

i have to extract data from 3 different tables.

is a single inner join better option or separate select statements ?

thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
690

hi check this..

for all entries is always better than the joins ..so kindly use the for all entries in the select statements..you can check the response time in the ST05 tcode.

regards,

venkat

5 REPLIES 5
Read only

Former Member
0 Likes
690

Hi,

Inner join used upon 3 tables is fine and the performance is also better. But dont use for more than 3 as the efficiency degrades.

Below is the sample code for an inner join on 3 tables.

SELECT stpo~stlnr stpo~idnrk mast~matnr mara~mtart stpo~menge  
INTO CORRESPONDING FIELDS OF TABLE zmat1 FROM mast  
JOIN stpo ON stpo~stlnr = mast~stlnr  
JOIN mara ON mara~matnr = mast~matnr  
WHERE stpo~stlty = 'M' "AND stpo~idnrk IN s_matnr  
AND mast~werks = 1000.

Pls reward if useful.

Thanks,

Sirisha.

Read only

Former Member
0 Likes
691

hi check this..

for all entries is always better than the joins ..so kindly use the for all entries in the select statements..you can check the response time in the ST05 tcode.

regards,

venkat

Read only

former_member156446
Active Contributor
0 Likes
690

Hi

If you are using Inner join u need to join with all the possible keys...then its affeciant, else using for all entries is fine..

Read only

Former Member
0 Likes
690

Hi,

Better to go with the FOR ALL ENTRIES.

Thanks,

Sriram Ponna.

Read only

Former Member
0 Likes
690

Hi,

If there are common key fields in the three tables, then inner join is a better option else its better to use for all entries to fetch the data.

If you want an example to join 3 tables, you can find it at this path in SAP

ABAPDOCU(Transaction)>ABAP Database Access>Open SQL>Read data>Inner Join.

you can find the following code*

DATA: BEGIN OF wa,

carrid TYPE spfli-carrid,

connid TYPE spfli-connid,

fldate TYPE sflight-fldate,

bookid TYPE sbook-bookid,

END OF wa,

itab LIKE SORTED TABLE OF wa

WITH UNIQUE KEY carrid connid fldate bookid.

SELECT pcarrid pconnid ffldate bbookid

INTO CORRESPONDING FIELDS OF TABLE itab

FROM ( ( spfli AS p

INNER JOIN sflight AS f ON pcarrid = fcarrid AND

pconnid = fconnid )

INNER JOIN sbook AS b ON bcarrid = fcarrid AND

bconnid = fconnid AND

bfldate = ffldate )

WHERE p~cityfrom = 'FRANKFURT' AND

p~cityto = 'NEW YORK' AND

fseatsmax > fseatsocc.

LOOP AT itab INTO wa.

AT NEW fldate.

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

ENDAT.

WRITE / wa-bookid.

ENDLOOP.

Reward if helpfull

Regards,

Adithya M