For all entries with inner join
Hi All,
I found some unusual thing.
i have written INNERJOIN along with FOR ALL ENTRIES and also INNERJOIN in loop..endloop. I have tested both programs with around 1000 records, i found that INNERJOIN with FOR ALL ENTRIES is taking more time compared to the other one. As we know FOR ALL ENTRIES with SIMPLE SELECT takes less time compared to select in loop..endloop. Anybody tell me is there any specific reason for this
thanks in advance
rajavardhana reddy
Have a look at this weblog by Dharmaveer Singh:
https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/2986 [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken]
Sudha
Similar Messages
-
For All Entries with two tables
Hi All,
Can we use FOR ALL ENTRIES with two tables. for example
SELECT * FROM MKPF INTO TABLE T_MKPF
WHERE BUDAT IN S_BUDAT.
SELECT * FROM MARA INTO TABLE T_MARA
WHERE MTART IN S_MTART AND
MAKTL IN S_MAKTL.
SELECT * FROM MSEG INTO TABLE T_MSEG
FOR ALL ENTRIES IN "T_MKPF AND T_MARA"
WHERE MBLNR EQ T_MKPF-MBLNR AND
MATNR EQ T_MARA-MATNR.
can we do it like this or any other way to do this plz tell. I waitting for your responce.
Thanks
JitendraHi,
u cannot do like this....chek some documentation on it..
1. duplicate rows are automatically removed
2. if the itab used in the clause is empty , all the rows in the source table will be selected .
3. performance degradation when using the clause on big tables.
Say for example you have the following abap code:
Select * from mara
For all entries in itab
Where matnr = itab-matnr.
If the actual source of the material list (represented here by itab) is actually another database table, like:
select matnr from mseg
into corresponding fields of table itab
where .
Then you could have used one sql statement that joins both tables.
Select t1.*
From mara t1, mseg t2
Where t1.matnr = t2.matnr
And T2 ..
So what are the drawbacks of using the "for all entires" instead of a join ?
At run time , in order to fulfill the "for all entries " request, the abap engine will generate several sql statements (for detailed information on this refer to note 48230). Regardless of which method the engine uses (union all, "or" or "in" predicates) If the itab is bigger then a few records, the abap engine will break the itab into parts, and rerun an sql statement several times in a loop. This rerun of the same sql statement , each time with different host values, is a source of resource waste because it may lead to re-reading of data pages.
returing to the above example , lets say that our itab contains 500 records and that the abap engine will be forced to run the following sql statement 50 times with a list of 10 values each time.
Select * from mara
Where matnr in ( ...)
Db2 will be able to perform this sql statement cheaply all 50 times, using one of sap standard indexes that contain the matnr column. But in actuality, if you consider the wider picture (all 50 executions of the statement), you will see that some of the data pages, especially the root and middle-tire index pages have been re-read each execution.
Even though db2 has mechanisms like buffer pools and sequential detection to try to minimize the i/o cost of such cases, those mechanisms can only minimize the actual i/o operations , not the cpu cost of re-reading them once they are in memory. Had you coded the join, db2 would have known that you actually need 500 rows from mara, it would have been able to use other access methods, and potentially consume less getpages i/o and cpu.
In other words , when you use the "for all entries " clause instead of coding a join , you are depriving the database of important information needed to select the best access path for your application. Moreover, you are depriving your DBA of the same vital information. When the DBA monitors & tunes the system, he (or she) is less likely to recognize this kind of resource waste. The DBA will see a simple statement that uses an index , he is less likely to realize that this statement is executed in a loop unnecessarily.
Beore using the "for all entries" clause and to evaluate the use of database views as a means to:
a. simplify sql
b. simplify abap code
c. get around open sql limitations.
check the links
http://www.thespot4sap.com/articles/SAPABAPPerformanceTuning_ForAllEntries.asp
The specified item was not found.
Regards,
Nagaraj -
Inner join and select for all entries with respect to performance
Hi Friends,
I just want to know which is more efficient with respect to performance the Inner join or select for all entries?which is more efficient? and how? can you explain me in detail ?
Regards,
DineshINNER JOIN->
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.
http://help.sap.com/saphelp_nw2004s/helpdata/en/cf/21ec77446011d189700000e8322d00/content.htm
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.
Not Recommended
Loop at int_cntry.
Select single * from zfligh into int_fligh
where cntry = int_cntry-cntry.
Append int_fligh.
Endloop.
Recommended
Select * from zfligh appending table int_fligh
For all entries in int_cntry
Where cntry = int_cntry-cntry. -
Inner join and select for all entries with respect to performance in SAP
Hi Friends,
I just want to know which is more efficient with respect to performance the Inner join or select for all entries?which is more efficient?
Regards,
DineshI did some testing a while ago and found that a JOIN is usually a bit more efficient than FOR ALL ENTRIES. This wasn't always the case though, so the best thing to do is to write it both ways and see which is faster.
Rob -
Select For all entries with multiple keys
Dear Developers,
im writing a program which reads the last the last mseg entry with bwart 101 and bwart 201 an writes it into different fields of a table. In dependance of the bwart the max-value of mkpf-budat should be moved into field wedat or wadat.
At the moment i use this coding:
loop at gt_daten assigning <fs_daten>.
select distinct max( budat ) from wb2_v_mkpf_mseg2 into <fs_daten>-wedat
where matnr_i = <fs_daten>-matnr
and werks_i = <fs_daten>-werks
and lgort_i = <fs_daten>-lgort
and bwart_i = '101'.
select distinct max( budat ) from wb2_v_mkpf_mseg2 into <fs_daten>-wadat
where matnr_i = <fs_daten>-matnr
and werks_i = <fs_daten>-werks
and lgort_i = <fs_daten>-lgort
and bwart_i = '201'.
endloop.
wb2_v_mkpf_mseg2 is a view combining mkpf an mseg by primary keys.
Searching the internet i read, using FOR ALL ENTRIES should be prefered to selectstatements in loops.
So i tried:
*selectstatement
select budat matnr_i werks_i lgort_i bwart_i from wb2_v_mkpf_mseg2 into table lt_mseg for all entries in gt_daten
where matnr_i = gt_daten-matnr
and werks_i = gt_daten-werks
and lgort_i = gt_daten-lgort
and ( bwart_i = '101' or bwart_i = '201' )
*Substitute the MAX( )-Function
sort lt_mseg descending by matnr werks lgort bwart budat.
delete adjacent duplicates from lt_mseg comparing matnr werks lgort bwart.
*Differ between wedat and wadat
loop at gt_daten assigning <fs_daten>.
loop at lt_mseg assigning <fs_mseg>
where matnr = <fs_daten>-matnr
and werks = <fs_daten>-werks
and lgort = <fs_daten>-lgort.
case <fs_mseg>-bwart.
when '101'.
<fs_daten>-wedat = <fs_mseg>-budat.
when '201'.
<fs_daten>-wadat = <fs_mseg>-budat.
endcase.
endloop.
Even in the dev-system this takes twice the time of the "nested" selects.
Imho this is because of the internal OR interpretation of the FOR ALL ENTRIES-statement and the size of the result.
Can somebody give me a hint, how to tune this code?
Select Inner join should be difficult because the target field differs, dependent of the value in bwart...
Thanks in advance!I understand that you are trying to capture the maximum value of posting date MKPF-BUDAT for movement types 101 and 201 for each combination of material, plant and storage location.
Few things, that makes the below coding more efficient at both application and database level and I confirmed this on an IDES sandbox
1. Along with MKPF and MSEG, there is another table WBGT, in the view WB2_V_MKPF_MSEG join and also WBGT has select condition restrictions imposed on its fields. So if this restriction impacts your selection you may want to do a INNER JOIN of MSEG with MKPF only (with MSEG as leading table, as it has an active secondary index with MATNR, WERKS, LGORT and BWART ) and also there won't be overhead from the unnecessary join with WBGT table whose fields you are not using.
2. The below SORT on lt_mseg will ensure that the record having greatest BUDAT will be at the top of all rows (least index) for each combination of MATNR, WERKS, LGORT and BWART.
3. DELETE ADJACENT DUPLICATES will ensure that only the top row (having greatest BUDAT) remains in the table lt_mseg for each combination of MATNR, WERKS, LGORT and BWART. This will ensure that subsequent READs with BINARY SEARCH will always and efficiently read the row with maximum value of BUDAT for each unique combination of MATNR, WERKS, LGORT and BWART.
4. The below logic will require more memory (even though it is more efficient performance wise) compared to direct SELECT with MAX for each MATNR, WERKS, LGORT and BWART in a LOOP the way you were doing before. So if the size of lt_mseg is causing memory issues, your logic with aggregate function MAX at database level will be your only option.
So, I propose you revise your coding like below for most optimal results
CHECK NOT gt_daten[] IS INITIAL.
*selectstatement
*SELECT budat matnr_i werks_i lgort_i bwart_i
* FROM wb2_v_mkpf_mseg2
* INTO TABLE lt_mseg
* FOR ALL ENTRIES IN gt_daten
* WHERE matnr_i = gt_daten-matnr
* AND werks_i = gt_daten-werks
* AND lgort_i = gt_daten-lgort
* AND ( bwart_i = '101' OR bwart_i = '201' ).
* The below SELECT is more economical than the one commented above
SELECT mkpf~budat mseg~matnr mseg~werks mseg~lgort mseg~bwart
FROM mseg INNER JOIN mkpf
ON mseg~mblnr = mkpf~mblnr AND
mseg~mjahr = mkpf~mjahr
INTO TABLE lt_mseg
FOR ALL ENTRIES IN gt_daten
WHERE mseg~matnr = gt_daten-matnr
AND mseg~werks = gt_daten-werks
AND mseg~lgort = gt_daten-lgort
AND ( mseg~bwart = '101' OR mseg~bwart = '201' ).
*Substitute the MAX( )-Function
SORT lt_mseg BY matnr werks lgort bwart DESCENDING budat.
DELETE ADJACENT DUPLICATES FROM lt_mseg COMPARING matnr werks lgort bwart.
*Differ between wedat and wadat
LOOP AT gt_daten ASSIGNING <fs_daten>.
READ TABLE lt_mseg ASSIGNING <fs_mseg>
WITH KEY matnr = <fs_daten>-matnr
werks = <fs_daten>-werks
lgort = <fs_daten>-lgort
bwart = '101' BINARY SEARCH.
IF sy-subrc = 0.
<fs_daten>-wedat = <fs_mseg>-budat.
ENDIF.
READ TABLE lt_mseg ASSIGNING <fs_mseg>
WITH KEY matnr = <fs_daten>-matnr
werks = <fs_daten>-werks
lgort = <fs_daten>-lgort
bwart = '201' BINARY SEARCH.
IF sy-subrc = 0.
<fs_daten>-wadat = <fs_mseg>-budat.
ENDIF.
ENDLOOP. -
For all entries with large sets
Hello All,
Does for all entries have restriction that the itab should not exceed the maximum entries? Look at code below:
select pernr raufpl raplzl catshours
from catsdb
into corresponding fields of table lit_catshrs
for all entries in itab
where pernr = itab-pernr
and status in ('10', '20', '30')
and workdate in s_date.
if itab have 7000 entries in production system, will the select statement cause a short dump such as DBIF_RSQL_INVALID_RSQL?
Thanks,
Alex MHi,
check the sequence of the fields in the internal table lit_catshrs
Because RSQL error occurs because of this.
and Whenevr you use for all entries of some Internal Table it is a must to check that
IF not ITAB[] Is initial.
< write the select>
endif.
Other performance related thing w.r.t to ABAP are
1) Dont use nested seelct statement
2) If possible use for all entries in addition
3) In the where addition make sure you give all the primary key
4) Use Index for the selection criteria.
5) You can also use inner joins
6) You can try to put the data from the first select statement into an Itab and then in order to select the data from the second table use for all entries in.
7) Use the runtime analysis SE30 and SQL Trace (ST05) to identify the performance and also to identify where the load is heavy, so that you can change the code accordingly
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/5d0db4c9-0e01-0010-b68f-9b1408d5f234
reward if useful
regards,
Anji -
Hi Guyz,
My requirement is to get data from 2 tables ..i wrote select statement but i wanna know if there is any otherway to do it for better peformance..
SELECT vbfa~vbeln
vbfa~vbelv
vbfa~rfmng
vbfa~vbtyp_n
ltap~pquit
INTO TABLE gt_del
FROM vbfa
LEFT OUTER JOIN
ltap ON
vbfavbeln = ltaptanum
AND vbfalgnum = ltaplgnum
FOR ALL entries IN gt_ltap
WHERE vbelv = gt_data
AND vbfa~vbeln = gt_ltap-tanum
AND vbfa~lgnum = gt_ltap-lgnum
AND vbfa~vbtyp_n = 'Q'.
gt_data having delvery numbers from the file.
plz advise..
regdsHi
Use FOR ALL ENTRIES
select lgnum " Warehouse Number / Warehouse Complex
lgtyp " Storage Type
lgpla " Storage Bin
skzua " Blocking Indicator: For Stock Removals (User)
skzue " Blocking indicator: for putaways (user)
spgru " Blocking reason
anzle " Number of storage units in storage bin
maxle " Max number of storage units in storage bin
btanr " Transfer order number of last stock transfer
btaps " Item in transfer order of last stock transfer
kzler " Indicator whether storage bin is empty
kzvol " Indicator whether storage bin is full
from lagp
into table t_lagp
where lgnum in s_lgnum.
if t_lagp[] is not initial.
select lgnum " Warehouse Number / Warehouse Complex
tanum " Transfer Order Number
mblnr " Number of Material Document
from ltak
into table t_ltak
for all entries in t_lagp
where lgnum eq t_lagp-lgnum.
endif.
if t_ltak[] is not initial.
select lgnum " Warehouse Number / Warehouse Complex
tanum " Transfer Order Number
tapos " Transfer order item
posnr " Item number of the SD document
matnr " Material Number
werks " Plant
charg " Batch Number
bestq " Stock Category in the Warehouse Management
*System
maktx " Material Description
from ltap
into table t_ltak
for all entries in t_ltak
where lgnum eq t_ltak-lgnum and tanum eq t_ltak-tanum.
endif.
Like this we have to filter the entires.
Thanks & Regards,
Chandralekha. -
For all entries with 2 internal table
HI experts.
How to use 2 for all entries in a select statement.
Below refer to my below code.
select vbeln matnr lfimg vgbel posnr from lips into corresponding fields of table
it_lips for all entries in it_likp where
vbeln = it_likp-vbeln and
matnr = it_mara-matnr.
I want to add another for all entries it_mara.
Please help me .Thanks in advanced.hi,
it is possible....
use this query...
declare another internal table of the same type as it_lips.
data : it_lips_final like it_lips.
select vbeln matnr lfimg vgbel posnr from lips into corresponding fields of table
it_lips for all entries in it_likp where
vbeln = it_likp-vbeln .
loop at it_lips.
read table it_mara into it_mara with key matnr = it_lips-matnr.
if sy-subrc = 0.
append it_lips to it_lips_final.
endif.
endloop.
refresh it_lips[].
it_lips[] = it_lips_final[]
what the above code does is selects all the entries of vbeln from lips and filters it in the loop reading it from mara checking for matnr value and finally
all the entries according to your requirement is there in it_lips_final which we move it to it_lips again...
this is something similar to writing a for all entries for 2 table.... but in another fashion
Regards
Siddarth -
Want to Avoid Loop for all entries with select query !!
Hi Guru's !
This is my following code . I want to avoid loop to improve the performance of program.
data: lt_cuhd type HASHED TABLE OF /sapsll/cuhd WITH UNIQUE key guid_cuhd,
ls_cuhd type /sapsll/cuhd.
data: lt_comments type STANDARD TABLE OF zss_comments,
ls_comments type zss_comments.
data: lv_objkey type string.
select * from /sapsll/cuhd into table lt_cuhd.
loop at lt_cuhd into ls_cuhd.
CONCATENATE ls_cuhd-corder '%' into lv_objkey. " Example 'Mum%'
select * from zss_comments into table lt_comments
where objkey like lv_objkey
AND guid_cuhd = ls_cuhd-guid_cuhd
AND event_id <> ''.
endloop.
I want
New code should be...using all entries no loop required.
*select * from zss_comments into table lt_comments
where objkey like lv_objkey
AND guid_cuhd = ls_cuhd-guid_cuhd
AND event_id <> ''.*why dont you add the object key also to lt_cuhd and once you fetch the data to lt_cuhd loop it and add the '%'
when looping use field symbols so that you dont have to use modify.
then use for all entries using lt_cuhd
i don't you can find a better way to add the % mark apart from looping but by this way only one select query will be done for
zss_comments
Thanks
Nafran -
2 for all entries with different condition
Hi
i have an internal 2 internal table which have the following field
ITAB1 : Stock category, plant, storage location , SKU code (those value are given though flat file)
ITAB2 : Grid value , meterial NO, SKU code (those values are determine through a FM where we export the SKU code and it will retreive the matnr and grid value in an ITAB2)
I have to do select FROM database MCHB
with the condition Grid value , material NO , Stock category, plant, storage location
Note that gris value and matnr are found in two different internal table i was thinking of doing for all entries but
is it possible to do for all entries from 2 internal table
SELECT FOROM MCHB
FOR ALL ENTRIES in ITAB1
FOR ALL ENTRIES in ITAB2
WHERE
grid value = itab2-gridvalue
matnr = itab2-matnr
stock cat = itab1-stock cat
plant = itab1-plant
storage location = itab1-storage location
Please help on how to tackle this?Hi,
You have to create a new third internal table with the fields matnr, grid value, stock category, plant and storage location....
Then process the itab1 and get the process the itab2 for the corresponding SKU Code (which I believe is the common field for both of the internal tables) and then populate the third internal table itab3...
Then use the itab3 for the FOR ALL ENTRIES.
Thanks
Naren -
What is the condition for using 'for all entries' and why?
what is the condition for using 'for all entries' and why? can any body tell the reason for this ? its a big favour of me .
regards,
ravi.hi,
for all entries is used to join two or more tables.
It is same as join but performance wise for all entries is more effective.
You can only use FOR ALL ENTRIES IN ...WHERE ...in a SELECT statement.
SELECT ... FOR ALL ENTRIES IN itab WHERE cond returns the union of the solution sets of all SELECT
statements that would result if you wrote a separate statement for each line of the internal table replacing the symbol
itab-f with the corresponding value of component f in the WHERE condition.Duplicates are discarded from the result
set. If the internal table itab does not contain any entries, the system treats the statement as though there were
no WHERE cond condition, and selects all records (in the current client).
for example:
SELECT * FROM sflight INTO wa_sflight
FOR ALL ENTRIES IN ftab
WHERE CARRID = ftab-carrid AND
CONNID = ftab-connid AND
fldate = '20010228'.
this condition, return all entries of the sflight
hen using FOR ALL ENTRIES the number of matching records is restricted to the number of records in the internal table. If the number of records in the database tables is too large then join would cause overheads in performance. Additionally a JOIN bypasses the table buffering.
So for all entries is used for filtering out the data from the two tables based on the entries in them.
Advantages:
1) For all entries avoids inner join & so the performance increases.
2) For specified values in 1 itab, if you to fetch values from other table you can use it.
3) Use of select stmt in loop is gets avoided, as u can use read statement on the the new itab. -
what is innerjoin & for all entries?
which one is used in which position,explain plzzzzzzzzzzzzzzzzz.
explain advantages & disadvantages?hi,
follow these links for knowing the difference between For all entries and joins.
http://www.erpgenie.com/abap/performance.htm#For%20all%20entries
http://blogs.ittoolbox.com/sap/db2/archives/for-all-entries-vs-db2-join-8912
1. INNER JOIN
DBTAB1 <----
> DBTAB2
It is used to JOIN two DATABASE tables
having some COMMON fields.
To Impove the perfomance of program you can use for all entries instead of your inner join...This is always preferable..But before make a check and make sure that your internal table is not empty.
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)
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
Advantages:
1) For all entries avoids inner join & so the performance increases.
2) For specified values in 1 itab, if you to fetch values from other table you can use it.
3) Use of select stmt in loop is gets avoided, as u can use read statement on the the new itab.
http://www.thespot4sap.com/articles/SAPABAPPerformanceTuning_ForAllEntries.asp -
INNER JOIN with FOR ALL ENTRIES IN Performance ?
I am using following the following <b>Select using Inner join with For All Entries in.</b>
SELECT kebeln kebelp kvbeln kvbelp
FROM ekkn AS k INNER JOIN ekbe AS b ON kebeln = bebeln
AND kebelp = bebelp
INTO TABLE gi_purchase
FOR ALL ENTRIES
IN gi_sales
WHERE k~mandt EQ sy-mandt
AND k~vbeln EQ gi_sales-vbeln
AND k~vbelp EQ gi_sales-posnr
AND b~budat EQ p_date.
If i am not doing inner join then I will have to do 2 select with for all entries in on ekkn and ekbe tables and then compare them.
<b>I want to know which one has better performance
Inner join with for all entries in
or
2 Selects with for all entries in</b>the join is almost aways faster:
<a href="/people/rob.burbank/blog/2007/03/19/joins-vs-for-all-entries--which-performs-better">JOINS vs. FOR ALL ENTRIES - Which Performs Better?</a>
<a href="http://blogs.ittoolbox.com/sap/db2/archives/for-all-entries-vs-db2-join-8912">FOR ALL ENTRIES vs DB2 JOIN</a>
Rob -
For All Entries is NOT better than INNER JOIN in most cases
I quote from Siegfried Boes' excellent post here: Will writing an inner join be better or creating a view?
For all the FOR ALL ENTRIES lovers ... there is no proof for these reappearing recommendation.
There is nearly nobody who receives forum points, who recommends FOR ALL ENTRIES instead of Joins. What is the reason ???
It is easier to prove the opposite. A Join is a nested loop inside the database, a FOR ALL ENTRIES is partly outside of the database. FOR ALL ENTRIES works in blocks, joins on totals.
FOR ALL ENTRIES are not recommded on really large tables, because the chances are too high that
too many records are transferred.
People prefer FOR ALL ENTRIES, because JOINs are not so easy to understand. Joins can go wrong, but with a bit of understanding they can be fixed.
Some Joins are slow and can not be fixed, but then the FOR ALL ENTRIES would be extremely slow.
There are several kinds of views:
- projection views, i.e. only one table involved just fields reduced
- join views, several tables, joins conditions stored in dictionary
- materialized views, here the joined data are actually stored in the database. Storing and synchronisation has to be done manually.
Only the last one creates real overhead. It should be the exception.
Join Views and Joins are nearly identical. The view is better for reuse. The join is better in complicated, becuase if the access goes wrong, it can often be fixed by adding a hint. Hints can not be added to views.
Abraham Bukit points out:
If it is cluster table, (you can't use join). If it is buffered table, I would also say avoid join.
If they all are transaction table which are not buffered and are not cluster tables.
He further supports Siegfried's statement that FAE is easier to undestand than INNER JOINs.
Thomas Zloch says, regarding buffered tables:
At least think twice, maybe compare runtimes if in doubt.
So, unless someone has some EVIDENCE that FOR ALL ENTRIES is better, I don't think we want to see this discussed further.
Kind regards
MattTo give food for thought here's an example I gave in a thread:
If you have a statement like
SELECT ... FOR ALL ENTRIES IN FAE_itab WHERE f = FAE_itab-f.
SAP sends it to the database depending how the parameter rsdb/prefer_union_all is set:
rsdb/prefer_union_all = 0 =>
SELECT ... WHERE f = FAE_itab[1]-f
OR f = FAE_itab[2]-f
OR f = FAE_itab[N]-f
You have some influence of the generated statement type: Instead of OR'ed fields an IN list can be used
if you have only a single coulmn N to compare:
rsdb/prefer_in_itab_opt parameter:
SELECT ... WHERE f IN (itab[1]-f, itab[2]-f, ..., itab[N]-f)
rsdb/prefer_union_all = 1 =>
SELECT ... WHERE f = FAE_itab[1]-f
UNION ALL SELECT ... WHERE f = FAE_itab[2]-f
UNION ALL SELECT ... WHERE f = FAE_itab[N]-f
see: Note 48230 - Parameters for the SELECT ... FOR ALL ENTRIES statement
As you can see for the 2nd parameter several statements are generated and combined with a UNION ALL,
the first setting generates statements with OR's (or uses IN if possible) for the entries in FAE_itab.
I give you a little example here (my parameters are set in a way that the OR's are translated to IN lists; i traced the execution in ST05)
Select myid into table t_tabcount from mydbtable
for all entries in t_table " 484 entries
where myid = t_table-myid .
ST05 trace:
|Transaction SEU_INT|Work process no 0|Proc.type DIA|Client 200|User |
|Duration |Obj. name |Op. |Recs.|RC |Statement|
| 640|mydbtable |PREPARE| | 0|SELECT WHERE "myid" IN ( :A0 , :A1 , :A2 , :A3 , :A4 ) AND "myid" = :A5|
| 2|mydbtable |OPEN | | 0|SELECT WHERE "myid" IN ( 1 , 2 , 3 , 4 , 5 ) AND "myid" = 72 |
| 2.536|mydbtable |FETCH | 0| 1403| |
| 3|mydbtable |REOPEN | | 0|SELECT WHERE "myid" IN ( 6 , 7 , 8 , 9 , 10 ) AND "myid" = 72 |
| 118|mydbtable |FETCH | 0| |
| 2|mydbtable |REOPEN | | 0|SELECT WHERE "myid" IN ( 11 , 12 , 13 , 14 , 15 ) AND "myid" = 72 |
| 3|mydbtable |REOPEN | | 0|SELECT WHERE "myid" IN ( 475 , 476 , 477 , 478 , 479 ) AND "myid" = 72 |
| 94|mydbtable |FETCH | 0| 1403| |
| 2|mydbtable |REOPEN | | 0|SELECT WHERE "myid" IN ( 480 , 481 , 482 , 483 , 484 ) AND "myid" = 72 |
You see the IN list contained 5 entries each , wich made up about 97 statements for all 484 entries.
For every statment you have a single fetch operation wich means a separate access to the database.
If you would replace the FAE with a join you would only have one fetch to the database.
With the example above we can derive these observations:
1. From database point of view these settings kill performance when you access a big table and/or have a lot of entries or columns in your FAE_itab. Furthermore, you hide information what data you will access
at all and thus you block the database from creating a more efficient execution plan because it DOESN'T KNOW wich data you will select in the next step. I.e. it may be more efficient to scan the table in one shot instead of having many index accesses - but the database can make this decision only if it can examine ONE statement that has ALL the information of what data to retrieve.
2. A second impact is that with every statement execution you trigger the allocation of database resources
wich will contribute to the overhead described above.
Said that, FAE can never be a replacement for joining big tables (think of having a table with thousands of records in a FAE table )
Edited by: kishan P on Nov 2, 2010 2:16 PM - Format Fixed -
Hi guru's what is the diff between for all entries & joins
hi guru's what is the diff between for all entries & joins
Hi Vasu,
Joins are used to fetch data fast from Database tables:
Tables are joined with the proper key fields to fetch the data properly.
If there are no proper key fields between tables don't use Joins;
Important thing is that don't USE JOINS FOR CLUSTER tableslike BSEG and KONV.
Only use for Transparenmt tables.
You can also use joins for the database VIews to fetch the data.
JOINS
... FROM tabref1 [INNER] JOIN tabref2 ON cond
Effect
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
|--||||||||--|
Example
Output a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
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 AND
FCONNID = PCONNID
WHERE P~CITYFROM = 'FRANKFURT'
AND P~CITYTO = 'NEW YORK'
AND F~FLDATE BETWEEN '20010910' AND '20010920'
AND FSEATSOCC < FSEATSMAX.
WRITE: / DATE, CARRID, CONNID.
ENDSELECT.
If there are columns with the same name in both tables, you must distinguish between them by prefixing the field descriptor with the table name or a table alias.
Note
In order to determine the result of a SELECT command where the FROM clause contains a join, the database system first creates a temporary table containing the lines that meet the ON condition. The WHERE condition is then applied to the temporary table. It does not matter in an inner join whether the condition is in the ON or WHEREclause. The following example returns the same solution as the previous one.
Example
Output of a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
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.
Note
Since not all of the database systems supported by SAP use the standard syntax for ON conditions, the syntax has been restricted. It only allows those joins that produce the same results on all of the supported database systems:
Only a table or view may appear to the right of the JOIN operator, not another join expression.
Only AND is possible in the ON condition as a logical operator.
Each comparison in the ON condition must contain a field from the right-hand table.
If an outer join occurs in the FROM clause, all the ON conditions must contain at least one "real" JOIN condition (a condition that contains a field from tabref1 amd a field from tabref2.
Note
In some cases, '*' may be specified in the SELECT clause, and an internal table or work area is entered into the INTO clause (instead of a list of fields). If so, the fields are written to the target area from left to right in the order in which the tables appear in the FROM clause, according to the structure of each table work area. There can then be gaps between table work areas if you use an Alignment Request. For this reason, you should define the target work area with reference to the types of the database tables, not simply by counting the total number of fields. For an example, see below:
Variant 3
... FROM tabref1 LEFT [OUTER] JOIN tabref2 ON cond
Effect
Selects the data from the transparent database tables and/or views specified in tabref1 and tabref2. tabref1 und tabref2 both have either the same form as in variant 1 or are themselves join expressions. The keyword OUTER can be omitted. The database tables or views specified in tabref1 and tabref2 must be recognized by the ABAP-Dictionary.
In order to determine the result of a SELECT command where the FROM clause contains a left outer join, the database system creates a temporary table containing the lines that meet the ON condition. The remaining fields from the left-hand table (tabref1) are then added to this table, and their corresponding fields from the right-hand table are filled with ZERO values. The system then applies the WHERE condition to the table.
Left outer join between table 1 and table 2 where column D in both tables set the join condition:
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
|--|||--|
Left Outer 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
a3
b3
c3
2
NULL
NULL
NULL
NULL
NULL
a4
b4
c4
3
3
e2
f2
g2
h2
|--||||||||--|
Example
Output a list of all custimers with their bookings for October 15th, 2001:
DATA: CUSTOMER TYPE SCUSTOM,
BOOKING TYPE SBOOK.
SELECT SCUSTOMNAME SCUSTOMPOSTCODE SCUSTOM~CITY
SBOOKFLDATE SBOOKCARRID SBOOKCONNID SBOOKBOOKID
INTO (CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
BOOKING-BOOKID)
FROM SCUSTOM LEFT OUTER JOIN SBOOK
ON SCUSTOMID = SBOOKCUSTOMID AND
SBOOK~FLDATE = '20011015'
ORDER BY SCUSTOMNAME SBOOKFLDATE.
WRITE: / CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
BOOKING-BOOKID.
ENDSELECT.
If there are columns with the same name in both tables, you must distinguish between them by prefixing the field descriptor with the table name or using an alias.
Note
For the resulting set of a SELECT command with a left outer join in the FROM clause, it is generally of crucial importance whether a logical condition is in the ON or WHERE condition. Since not all of the database systems supported by SAP themselves support the standard syntax and semantics of the left outer join, the syntax has been restricted to those cases that return the same solution in all database systems:
Only a table or view may come after the JOIN operator, not another join statement.
The only logical operator allowed in the ON condition is AND.
Each comparison in the ON condition must contain a field from the right-hand table.
Comparisons in the WHERE condition must not contain a field from the right-hand table.
The ON condition must contain at least one "real" JOIN condition (a condition in which a field from tabref1 as well as from tabref2 occurs).
Note
In some cases, '*' may be specivied as the field list in the SELECT clause, and an internal table or work area is entered in the INTO clause (instead of a list of fields). If so, the fields are written to the target area from left to right in the order in which the tables appear in the llen in der FROM clause, according to the structure of each table work area. There can be gaps between the table work areas if you use an Alignment Request. For this reason, you should define the target work area with reference to the types of the database tables, as in the following example (not simply by counting the total number of fields).
Example
Example of a JOIN with more than two tables: Select all flights from Frankfurt to New York between September 10th and 20th, 2001 where there are available places, and display the name of the airline.
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 FCARRID = PCARRID AND
FCONNID = PCONNID )
INNER JOIN SCARR AS C
ON FCARRID = CCARRID
WHERE P~CITYFROM = 'FRANKFURT'
AND P~CITYTO = 'NEW YORK'
AND F~FLDATE BETWEEN '20010910' AND '20010920'
AND FSEATSOCC < FSEATSMAX.
WRITE: / WA-CARR-CARRNAME, WA-FLIGHT-FLDATE, WA-FLIGHT-CARRID,
WA-FLIGHT-CONNID.
ENDSELECT.
And for all entries,
this will help u.
use of FOR ALL ENTRIES:
1. INNER JOIN
DBTAB1 <----
> DBTAB2
It is used to JOIN two DATABASE tables
having some COMMON fields.
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.
cheers,
Hema.
Maybe you are looking for
-
Permit user to administrate Model AND have read-only attributes
This issue concerns SQL Server Master Data Services 2012 I have a scenario where the same user is handling data and doing version management. Now I want to make one attribute in one specific entity read-only as I want to make sure the attribute is ne
-
Logical Model vs. Process Model
Some questions on SDDM 3.1.4 support for internal consistency of a design: 1. Can I have the same Information Store on more than one Data Flow Diagram (in the same design)? When I try this, either by creating a new one on the second DFD and trying to
-
I am trying to allow a blocked plug in (Java) on a trusted site. Your directions say that a red Lego-looking icon will appear in the address bar. I do not have this icon. So, how can I allow Java to work on this site? I have installed the latest vers
-
Select Accounting View in BDC Program
Hi Experts, I am working on a BDC program in which I have to change the Accounting view data for Materials(MM02). Each material has diferent number of views. So How can I select only the Accounting View when changing Material data through BDC. Than
-
Why can't I invite people to events in Calendar app?
When I open my calendar app and click to add a new event, the "Invitees" field does not appear and I cannot invite people to events. The field DOES appear on my iPhone (which is setup with a separate Apple ID). Does anyone know why this is happening?