Sei sulla pagina 1di 6

7/2/2014

howto use inner join and for all entries | SCN

7/2/2014 howto use inner join and for all entries | SCN Hi, Guest Log On Join

Hi, Guest

Search the Community

Products

Services & Support

About SCN

Industries

Training & Education

Partnership

Lines of Business

Events & Webinars

Innovation

7 Replies Latest reply: May 22, 2007 1:20 PM by Suresh Babu Aluri Share 0
7 Replies
Latest reply: May 22, 2007 1:20 PM by Suresh Babu Aluri
Share
0
Tweet 0
Like
0
deepak jaiswal
May 22, 2007 1:03 PM
how to use inner join and for all entries
This question is Assumed Answered.
hi all experts,
i am new to abap .plz help me by providing details about joining two tables
using inner join to fetch some data into an internal table.
now ,iff we use for all entries in place of inner join for fetching the same relevant data .
what should we do.
please give some sample code for the same example using with inner join and for all enteries.
Helpful Answer by Sandeep Ranade
3642 View s
Topics: abap
Average User Rating
(0 ratings)
Sandeep Ranade May 22, 2007 1:10 PM (in response to deepak jaisw al)
Helpful Answer
Re: how to use inner join and for all entries
Hi,
Inner Join : here you are going to use two database tables having common fields, on the basis of
which you will fetch the data.
ex. select afield1 bfield2 a~field3 into table itab where DB1 as a join DB2 as b on <specify the
condtion on common field>
For all entries: Here at first you are going to fetch data from Db1 into itab1 for specified condition.
then again you will use one more select query to fetch the values from DB2 for the corresponding
entries in internal table itab1.
Ex select f1 f2 field into table itab1 from DB1 where <condition>
select f3 f4 into tabe itab2 from DB2 for all entries in itab1
where field = itab1-field and <other conditions>
Thanks
sandeep
Reward if helpful
Like (0)
Sarath kumar Chandrasekharan May 22, 2007 1:12 PM (in response to deepak jaisw al)
Re: how to use inner join and for all entries

7/2/2014

howto use inner join and for all entries | SCN

Hi Deepak, To use "for all entries" is as 1. declare internal tables for both
Hi Deepak,
To use "for all entries" is as
1. declare internal tables for both the tables you declare.
2.select the values into ur header tables's internal table first from ur internal table.
3.select the value from item table using the header table's internal table like
select *
into table <item table's internal table>
from <item table>
for all entries in <header table's internal table>
where <field of item table = field of header table's internal table>
check this will work.
Like (0)
Priyanka Neelam May 22, 2007 1:13 PM (in response to deepak jaisw al)
Re: how to use inner join and for all entries
Hi,
The Inner join can be very performant when you use combined table like vbak/vbap/vbep or
ekko/ekpo/eket or mara/marc/mard,
The for all entries statement will be less performant if you have a lot of records ( and don't forget, you
have in most cases to delete duplicates, so
)
In my opinion, it really depends.
If you have doubt in your report, just do a test
Anyway, something sure is that obviously there is no better statement between "for all entries" and
"Inner Join". If there was, everybody would know it.
http://www.sap-img.com/abap/performance-tuning-for-data-selection-statement.htm
Inner join :
This is used to join two tables with matchin fields.
This is a EQUI join type means, record will be fetched if and only if joining condition is is matchin for
both tables.
This is a INNER JOIN type of SQL.
This refers two or more tables with table fields.
For all entries:
This is OUTER JOIN type of SQL.
Means, all record will be fetched from left table on joining condition. and from right table if conditions
satisfies that record will be fetched otherwise null will be retured as data.
FOR ALL ENTRIES is an effective way of doing away with using JOIN on two tables.
You can check the below code -
SELECT BUKRS BELNR GJAHR AUGDT
FROM BSEG
INTO TABLE I_BSEG
WHERE BUKRS =
SELECT BUKRS BELNR BLART BLDAT
FROM BKPF
INTO TABLE I_BKPF
FOR ALL ENTRIES IN I_BSEG
WHERE BUKRS = I_BSEG-BUKRS
AND BELNR = I_BSEG-BELNR
AND BLDAT IN SO_BLDAT.
*******************************8
look another example
what is the use of FOR ALL ENTRIES
1. INNER JOIN
DBTAB1 <----
> DBTAB2
It is used to JOIN two DATABASE tables
having some COMMON fields.

7/2/2014

howto use inner join and for all entries | SCN

2. Whereas For All Entries, DBTAB1 <---- > ITAB1 is not at all related to
2.
Whereas
For All Entries,
DBTAB1 <----
> ITAB1
is not at all related to two DATABASE tables.
It is related to INTERNAL table.
3.
If we want to fetch data
from some DBTABLE1
but we want to fetch
for only some records
which are contained in some internal table,
then we use for alll entries.
*----
1. simple example of for all entries.
2. NOTE THAT
In for all entries,
it is NOT necessary to use TWO DBTABLES.
(as against JOIN)
3.
use this program (just copy paste)
it will fetch data
from T001
FOR ONLY TWO COMPANIES (as mentioned in itab)
4
REPORT abc.
DATA : BEGIN OF itab OCCURS 0,
bukrs LIKE t001-bukrs,
END OF itab.
DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
*----
itab-bukrs = '1000'.
APPEND itab.
itab-bukrs = '1100'.
APPEND itab.
*----
SELECT * FROM t001
INTO TABLE t001
FOR ALL ENTRIES IN itab
WHERE bukrs = itab-bukrs.
*----
LOOP AT t001.
WRITE :/ t001-bukrs.
ENDLOOP.
Overall, All records from left table will be selected where as only matching record will be updated in
resultset from right table.
This generally uses ITAB as RIGHT side comparisoin.
While using For all entried Ensure that, ITAB should not be empty and it fetched unique records only.
Regards,
Priyanka.
Like (0)

7/2/2014

howto use inner join and for all entries | SCN

Pavan Valluri May 22 2007 1:15 PM (in response to deepak jaisw al) Re: how
Pavan Valluri May 22 2007 1:15 PM (in response to deepak jaisw al)
Re: how to use inner join and for all entries
Hi deepak
Inner join is used to join two different tables by relating them by comparing one of their common
fields
Here is the sample code for inner join
SELECT ekko~lifnrekko~ebelnekko~knumvekko~bedat
ekpo~werksekpo~matnrekpo~txz01ekpo~werks
*
ekpo~netwr
ekpo~aedat
ekbe~ebelp ekbe~belnr
lfa1~name1
INTO CORRESPONDING FIELDSOF TABLEint_outtab
FROM(((ekko
JOINekbeON ekbe~ebeln=ekko~ebelnAND
ekbe~vgabe='2'
)
JOINekpoONekpo~ebeln=ekko~ebeln AND
ekpo~ebelp=ekbe~ebelp)
JOINlfa1ONlfa1~lifnr=ekko~lifnr)
WHERE ekko~lifnr = P_lifnr AND
ekko~ebelnIN S_ebeln AND
*
ekpo~werksIN S_werksAND
ekbe~vgabe='2'.
Use of FOR ALL Entries
Outer join can be created using this addition to the where clause in a select statement. It speeds up
the performance tremendously, but the cons of using this variation are listed below
Duplicates are automatically removed from the resulting data set. Hence care should be taken that
the unique key of the detail line items should be given in the select statement.
If the table on which the For All Entries IN clause is based is empty, all rows are selected into the
destination table. Hence it is advisable to check before-hand that the first table is not empty.
If the table on which the For All Entries IN clause is based is very large, the performance will go down
instead of improving. Hence attempt should be made to keep the table size to a moderate level.
<b>Not Recommended</b>
Loopatint_cntry.
Selectsingle*fromzflighintoint_fligh
wherecntry=int_cntry-cntry.
Appendint_fligh.
Endloop.
<b>Recommended</b>
Select*fromzflighappendingtableint_fligh
Forallentriesinint_cntry
Wherecntry=int_cntry-cntry.
rewards if helpfull
Regards
Pavan
Like (0)
Deniz Toprak May 22, 2007 1:17 PM (in response to deepak jaisw al)
Re: how to use inner join and for all entries

7/2/2014

howto use inner join and for all entries | SCN

you can join two tables like that: assume the tables are spfli and sbook(just assume),
you can join two tables like that:
assume the tables are spfli and sbook(just assume), now we can join these two tables:
select spcarrid spconnid sb~price from spfli as sp
inner join sbook as sb
on
spconnid = sbconnid.
endselect.
I hope That helps
deniz.
Like (0)
Pramod Kumar Upadhyay May 22, 2007 1:18 PM (in response to deepak jaisw al)
Re: how to use inner join and for all entries
Hi,
Please look at this sample code where there is JOIN on EKKO and EKPO tables
and FOR ALL ENTRIES is used on the table LIPS
IF NOT i_lips[] IS INITIAL.
SELECT k~ebeln
p~ebelp
k~lifnr
k~ekorg
p~werks
p~labnr
FROM ekko AS k INNER JOIN ekpo AS p
ON kebeln EQ pebeln
INTO TABLE i_ekpo
FOR ALL ENTRIES IN i_lips
WHERE k~ebeln = i_lips-vgbel AND
p~ebelp = i_lips-vgpos+1(5).
IF sy-subrc NE 0.
MESSAGE i000 WITH text-i03.
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.
Thanks
Pramod
Like (0)
Suresh Babu Aluri May 22, 2007 1:20 PM (in response to deepak jaisw al)
Re: how to use inner join and for all entries
hi,
tables: mara,makt.
types: begin of itab
matnr like mara-matnr,
maktx lik emakt-maktx,
ernam like mara-ernam,
end of itab.
data: itab1 like itab occus 0 with header line.
[for joins]
select matnr maktx ernam from mara as a inner join
makt as b into table itab1
where amatnr = bmatnr and sy-langu = 'EN'.
[for all entries]
select matnr maktx ernam from mara as a for all entries in
makt as b into table itab1
where amatnr = bmatnr and sy-langu = 'EN'.

7/2/2014

howto use inner join and for all entries | SCN

if helpful reward some points. with regards, suresh babu aluri. Like (0) Share 0 Tweet
if helpful reward some points.
with regards,
suresh babu aluri.
Like (0)
Share
0
Tweet 0
Like
0
Site Index
Contact
Us
Privacy
Terms of
Use
SAP Help Portal
Legal Disclosure
Follow SCN
Copyright