‎2008 May 05 6:13 PM
hi all,
i have to extract data from 3 different tables.
is a single inner join better option or separate select statements ?
thanks
‎2008 May 05 6:17 PM
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
‎2008 May 05 6:17 PM
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.
‎2008 May 05 6:17 PM
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
‎2008 May 05 6:25 PM
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..
‎2008 May 05 6:29 PM
‎2008 May 05 6:30 PM
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