Inner join searches too many entries
Hi experts,
In a user exit following code is used:
DATA : h_rsnum LIKE afko-rsnum,
h_charg LIKE resb-charg,
h_matnr LIKE resb-matnr,
SELECT SINGLE rsnum INTO h_rsnum
FROM afko
WHERE aufnr = x_bncom-aufnr.
IF sy-subrc = 0 .
SELECT resbcharg resbmatnr
INTO (h_charg, h_matnr)
FROM mara INNER JOIN resb
ON maramatnr = resbmatnr
WHERE resb~rsnum = h_rsnum
AND resb~charg NE space
AND maramtart = 'HALB' OR maramtart = 'FERT'.
ENDSELECT.
Goal of the source code is to detemine the reservation number of a process order. From table RESB with key h_rsnum, the material nb and the batch nb of the single material with material type HALB or FERT needs to be selected.
During debugging I found out that this code searches into a very long list of materials before ending up with the correct h_charg and h_matnr.
If the condition resb~rsnum = h_rsnum would be taken into account when creating the inner join, the list would only contain 20 materials maximum.
Can this behaviour be changed and how to do it?
Rgds,
Suzy
if this is inside a user exit 1st of all why are you using a select endselect and i dont see you take that in to a table which means your only looking for one record.
about you tell that before the inner join taking the where condition into consideration. I dont think it will be possible sine normally after making the join it should go for the where condition anyway ill try to check on it and see.
sometimes Siegfried might know an answer dont know if he saw this.
Nafran
Edited by: Nafran Shiraz on Jun 4, 2009 12:36 PM
Similar Messages
-
Inner joins Vs for all entries
Hi All,
Pls let me know
the differences b/w innerjoins and for all entries,,,,which is the best option and Y??
Thanks in Advance,
ByeHi!
INNER JOIN is used if we want to retrieve some data from more than one table.
FOR ALL ENTRIES is used if we want some data from a table based on some conditions of some other table.
Using several nested INNER JOIN statements can be inefficient and cause time out if the tables become too big in the future."
In ABAP, these joins are first split by the ABAP processor and then sent to the database, with the increase in DATA in production system, these joins tend to give way if your database keeps growing larger and larger.
You should rather use "FOR ALL ENTRIES IN" (Tabular conditions), which is a much efficient way as far as performance is concerned.
Check these links:
inner joins and for all entries
inner join and for all entries
Reward points if it helps.
Regards
Sudheer -
Coupling INNER JOIN with FOR ALL ENTRIES statement
Hi All,
I am coupling INNER JOIN with FOR ALL ENTRIES statement .....
Would you please highlight its implications ?? Is it a best practise ?
Is it advicable to use MULTIPLE INNER JOINs with a FOR ALL ENTRIES ???
SORT itab BY matnr.
IF NOT itab[] IS INITIAL.
SELECT epmatnr epebeln ep~ebelp
epwerks epmenge ep~netpr
ekps_psp_pnr ebbelnr eb~menge
INTO TABLE iekpo
FROM ekpo AS ep
INNER JOIN ekkn AS ek
ON ekebeln = epebeln
AND ekebelp = epebelp
INNER JOIN ekbe AS eb
ON ebebeln = epebeln
AND ebebelp = epebelp
AND eb~bwart = '101'
FOR ALL ENTRIES IN itab
WHERE ep~matnr = itab-matnr.
IF sy-subrc EQ 0.
SORT iekpo BY matnr werks.
LOOP AT itab ASSIGNING <itab>.
READ TABLE iekpo WITH KEY matnr = <itab>-matnr
werks = <itab>-werks
BINARY SEARCH.
IF sy-subrc EQ 0.
MOVE iekpo-matnr TO itab1-matnr.
MOVE iekpo-ebeln TO itab1-ebeln.
MOVE iekpo-ebelp TO itab1-ebelp.
MOVE iekpo-netpr TO itab1-poprice.
MOVE iekpo-werks TO itab1-werks.
MOVE iekpo-menge TO itab1-menge1.
MOVE iekpo-menge1 TO itab1-menge2.
MOVE iekpo-belnr TO itab1-belnr.
MOVE iekpo-ps_psp_pnr TO itab1-pspel.
MOVE <itab>-pspel TO itab1-tpspel.
MOVE <itab>-sobkz TO itab1-sobkz.
MOVE <itab>-fo_qty TO itab1-fo_qty.
MOVE <itab>-schgt TO itab1-schgt.
MOVE <itab>-postp TO itab1-postp.
MOVE <itab>-beskz TO itab1-beskz.
pend_qty = iekpo-menge1 - iekpo-menge2.
MOVE pend_qty TO itab1-pending.
APPEND itab1.
pend_qty = 0.
ENDIF.
ENDLOOP.
ENDIF.
ENDIF.
ENDIF.
Regards
Jaman
Edited by: ABAP Techie on Sep 15, 2008 12:39 PM
Edited by: ABAP Techie on Sep 15, 2008 12:41 PMbest practise ... don't know ... it is allowed and o.k.
If possible you should of coourse to have no FOR ALL ENTRIES at all !
Joins, there is no general rule, check indexes etc.
The first SORT, I don't that it help for anything, use it together with the delete adjacent duplicates if you expect duplicates in the driver table.
o.k., it can help, if there is a loop afterwards and an append inside, because the new table itab1 is then sorted.
Siegfried -
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 -
Inner Join with For All Entries - 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><b></b>An Inner Join with for all entries should be done if you add this....
IF NOT gi_sales[] IS INITIAL.
SELECT k~ebeln k~ebelp k~vbeln k~vbelp
FROM ekkn AS k INNER JOIN ekbe AS b ON k~ebeln = b~ebeln
AND k~ebelp = b~ebelp
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.
ENDIF.
Also, while you use an index or the complete key for the SELECT, your not going to suffer from lack of performance -;)
Greetings,
Blag. -
Data Warehouse Synchronization server - too many entries
I am having problems with app advisor not getting performace data. I believe that it is due to the Data Warehouse Synchronization
server having too many entries as I only have 1. How do I remove a server?Seems you need to restore the OperationsManager Database from the previous backup, try the methods in the kb.
http://support.microsoft.com/kb/2771934/en-gb
http://social.technet.microsoft.com/Forums/en-US/0f80e33e-243a-44ab-ba1a-e73ec421de03/two-dw-synchronization-server-instances-by-mistake
Juke Chou
TechNet Community Support -
HT1212 my phone is disabled due to too many entries of passcode. how do i unlock?
my phone is disabled due to too many entries of passcode. How do I unlock?
This will erase everything off your phone, but you need to do a restore. If iTunes wont let you restore it, while plugged in to the computer (with iTunes open), press and hold both the lock and home buttons, then release the lock button when screen goes black.
-
Replacing a inner join with for all entries
Hi Team,
In a already developed program I am replacing a inner join with select query follow up with for-all-entris and passing the data to final internal table but in both the case the result should be same then only my replacement will be correct. But my no records in both cases differs. This happening because when i am selecting data from first data base table is 32 lines. then I am doing fo-all-entries moving all the duplicate entries then the no records are four. but in final internal table i am looping the first internal table. So in final internal table the no of records are 32. But in inner join query the records are 16.So please let me know how resolve this issue?
Thanks and REgards
DeepaHi Thomas,
Thanks for ur suggestion.
The solved that in below.
In select query I did not change anything The way I had written the code was correct.
I think many of us know how to write that how to make the performance better in that way.
I made the change when I transfered the to final internal table.
The original Inner join code:
select a~field1 a~field2 a~field3 b~field2 b~field3 b~field4
from dbtab1 as a inner join dbtab2 as b
on a~field1 = b~field1 into it_final where
a~field1 in s_field1. [Field1 in both the table are key field]
Before code:
Sort itab1 by key-fields.
sort itab2 by keyfields.
loop at itab1 into wa1.
move: wa1-field1 to wa_final-field1,
wa1-field2 to wa_final-field2,
wa1-field3 to wa_final-field3.
read table itab2 into wa2 witk key field1 = wa1-field1 binary search.
if sy-subrc = 0.
move : wa2-field2 to wa_final-field4,
wa2-field3 to wa_final-field5,
wa2-field4 to wa_final-field6.
append wa_final to it_final.
endif.
Clear : wa1, wa2, wa_final.
endloop.
In this case if the one key fieild value is not present there in second internal table but its there in first internal table still it will read that row with 2nd internal values having zeroes. Normally what does not happen in inner join case if the key field value will same in both the case ,then that will fetch only those rows.
Changed Code
loop at itab1 into wa1.
read table itab2 into wa2 witk key field1 = wa1-field1 binary search.
if sy-subrc = 0.
move: wa1-field1 to wa_final-field1,
wa1-field2 to wa_final-field2,
wa1-field3 to wa_final-field3.
move : wa2-field2 to wa_final-field4,
wa2-field3 to wa_final-field5,
wa2-field4 to wa_final-field6.
append wa_final to it_final.
endif.
Clear : wa1, wa2, wa_final.
endloop.
In this case the values will read to final internal table if both key field matches.
With Regards
Deepa -
Inner Joins vs For All Entries - performance query
Hi All,
I'm a bit confused here... I see lots and lots (and lots...) of postings from people asking how to get data from multiple tables.
To me the immediate answer is to use joins in my select statement to reduce the database load but more and more I see people suggesting FOR ALL ENTRIES is better from a performance perspective.
Now, simple question time, which is more efficient in the real world when doing something like the following:- (this is a basic example but I'm sure you know what I mean.)
Select *
into table lt_sales_data
from vbap as vbap
inner join vbak as vbak
on vbak~vbeln eq vbap~vbeln
where vbak~vbeln in so_vbeln.
or
Select *
into table lt_vbak_data
from vbak
where vbeln in so_vbeln.
if lt_vbak_data[] is not initial.
select *
into table lt_vbap_data
from vbap
for all entries in lt_vbak_data
where vbeln eq lt_vbak_data-vbeln.
endif.
Basically I want to know whether joins or for all entries is better from a database performance perspective.
I want to know why as well so please don't just post links, random cut and paste answers or one liners. I'm convinced for all entries is slower but am willing to be persuaded otherwise if someone can show me proof.
Thanks,
Gareth.Thanks to all the opinions so far... You've backed up what I suspected although I maybe wasn't clear enough with my question and desired result. I was hoping someone could produce some hard and fast guidelines from SAP themselves dictating which is the better method. I know 10 years ago I was taught to use joins and to keep my database access to minimal levels, using keyed reads where applicable and using internal tables to filter data where I couldn't use key fields.
Gautham, I am aware of SM30 but that doesn't answer the general question I was asking. I've obviously used SM30 to run some comparisons but I was really hoping someone could give me a definitive answer based on hard facts or from attending some training at SAP recently. And no points for asking for them
Tamás, I agree with what you are saying about runing many comparisons - it appears to be dependant on any number of criteria which means each case may require different code. I've not managed to find a consistent comparison of the two methods that would lead me to use one method or the other...
Karan, thanks for your feelings but it doesn't really help me! Why/how does it retrieve the data faster than a join? Have you got testing/proof to back this up?
Raam, thanks for those links - they are interesting reads and seem to go through the same arguments I'm currently considering. Although I still don't have a definitie answer!
Amit, I understand exactly what yuo are saying about myths and urban legends That was my motivation for this post. To bo honest, it seems to me that a lot of the "newer" ABAP coders always go for FOR ALL ENTRIES but I wanted to know - is there a reason or do they all just cut and paste off SDN?! Are they all just scared of complex inner joins?! What would you all make of this Select statement for example? -
select afvc~arbid
afko~aufnr
aufk~objnr
afko~plnnr
afko~plnal
afko~aufpl
afko~zaehl
afpo~matnr
makt~maktx
afvc~vornr
afvc~ltxa1
afvu~aplzl
afvu~usr10
afvv~meinh
afvv~bmsch
afvv~vge02
afvv~vgw02
afvv~mgvrg
afab~aplzl_vor
into table lt_recipe_orders
from afko as afko
inner join aufk as aufk
on aufk~aufnr eq afko~aufnr
inner join afpo as afpo
on afpo~aufnr eq afko~aufnr
inner join makt as makt
on makt~matnr eq afpo~matnr
inner join afvc as afvc
on afvc~aufpl eq afko~aufpl
inner join afvu as afvu
on afvu~aufpl eq afvc~aufpl
and afvu~aplzl eq afvc~aplzl
inner join afvv as afvv
on afvv~aufpl eq afvu~aufpl
and afvv~aplzl eq afvu~aplzl
left outer join afab as afab
on afab~aufpl_nch eq afvu~aufpl
and afab~aplzl_nch eq afvu~aplzl
for all entries in t_resources
where afko~gltrs ge v_start_date
and afko~gstrs le v_start_date
and afko~plnty eq gc_task_list_type_2
and afpo~dwerk eq v_werks
and makt~spras eq sy-langu
and afvc~arbid eq t_resources-objid.
Twinkal, I've always thought less DB hits is a better performing program too - the above example compares 2 db hits to 1... I don't have issues with complex joins because I've used them so long so can discount that problem but do agree that less DB hits is the ultimate goal. Providing of course the Selects you write are actually efficient in themselves.
Murthy, if you build your select statement correctly duplicate records can be avoided in most cases. How can you say a join statement will hit the database more when in my example there is 1 DB hit compared to 2 for a for all entries? And I'd love to know the reasoning behind never using a join on more than 2 tables?! Is that just an urban myth?!
Thomas, I've just been looking at some of Siegfried's posts and like what I am reading. As you say, using full keys via joins is essential.
Gareth. -
Hi Expert,
Could you please help me in this inner join , Inner join is performance wise is not good so i want to replace instated of inner join for all entries. But when i am checking records of internal table there is difference. in inner join i am getting 11 records but for all entries i am getting 5 records .
Please help me out where excatly i have done mistake.
SELECT maralvorm maramatkl
maramatnr marameins
maraprdha maraspart
marcausss marcbearz
marcbeskz marcbstmi
marc~wzeit
marcdisgr marcmaabc * marcdismm marcdispo
marcdispr marcdzeit
marcplifz marcdisls
marcbstma marcbstrf
marc~basmg
marceisbe marcfevor
marcfxhor marclvorm
marcmatnr marcmmsta
marcprctr marcsobsl
marctranz marcwerks
marc~xchar
marclgpro marcfhori
marc~rgekz
mbewbklas mbewbwkey
mbewlbkum mbewsalk3
mbewmatnr mbewpeinh
mbewstprs maktmaktx
maktmatnr cepcabtei
cepc~prctr
marcschgt marcminbe
marc~ekgrp
marc~eprio
marc~kausf
marc~shflg
marc~shzet
marc~fabkz
marc~lgrad
marc~shpro
marc~eislo
marc~rwpro
marc~lgfsb
marczzfdwe marczzfdwi
marczzsspe marczzsspi
INTO TABLE i_matl
FROM ( mara
INNER JOIN marc
ON marcmatnr = maramatnr
INNER JOIN mbew
ON mbewmatnr = marcmatnr
AND mbewbwkey = marcwerks
INNER JOIN makt
ON maktmatnr = maramatnr
INNER JOIN cepc
ON cepcprctr = marcprctr
AND cepcdatbi >= sy-datum ) "* WHERE maralvorm IN sp$00094
AND mara~matkl IN sp$00084
AND mara~meins IN sp$00091
AND mara~prdha IN sp$00066
AND mara~spart IN sp$00085
AND marc~disgr IN sp$00089
AND marc~dismm IN sp$00067
AND marc~dispo IN sp$00061
AND marc~dispr IN sp$00083
AND marc~fevor IN sp$00090
AND marc~lvorm IN sp$00092
AND marc~mmsta IN sp$00086
AND marc~beskz IN s_beskz
AND marc~sobsl IN sp$00068
AND marc~werks IN sp$00062
AND marc~xchar IN sp$00093
AND marc~maabc IN sp$00099
AND marc~lgrad IN s_lgrad
AND marc~lgpro IN s_lgpro
AND marc~rwpro IN s_rwpro
AND marc~lgfsb IN s_lgfsb
AND marc~schgt INs_schgt * AND marc~shflg IN s_shflg
AND marc~shzet IN s_shzet
AND marc~fabkz IN s_fabkz
AND marc~shpro IN s_shpro
AND marc~eislo IN s_eislo
AND marc~zzfdwe IN s_zzfdwe
AND marc~zzfdwi IN s_zzfdwi
AND marc~zzsspe IN s_zzsspe
AND marc~zzsspi IN s_zzsspi
AND mbew~bklas IN sp$00063
AND mbew~lbkum IN sp$00088
AND makt~maktx IN sp$00059
AND makt~spras = c_en
AND makt~matnr IN sp$00060
AND cepc~prctr IN sp$00087.
I am using for all entries
fetching data from marc data base table
SELECT matnr werks lvorm xchar mmsta
maabc ekgrp dispr dismm
dispo plifz ausss disls
beskz sobsl minbe eisbe
bstmi bstma bstrf fhori
rgekz fevor bearz tranz
basmg dzeit wzeit lgrad
prctr fxhor lgpro disgr
kausf rwpro lgfsb schgt
eprio shflg shzet fabkz
shpro eislo zzfdwe zzfdwi
zzsspe zzsspi
FROM marc INTO TABLE i_marc
WHERE werks IN sp$00062
AND lvorm IN sp$00092
AND xchar IN sp$00093
AND mmsta IN sp$00086
AND maabc IN sp$00099
AND dispr IN sp$00083
AND dismm IN sp$00067
AND dispo IN sp$00061
AND beskz IN s_beskz
AND sobsl IN sp$00068
AND fevor IN sp$00090
AND lgrad IN s_lgrad
AND lgpro IN s_lgpro
AND disgr IN sp$00089
AND rwpro IN s_rwpro
AND lgfsb IN s_lgfsb
AND schgt IN s_schgt
AND shflg IN s_shflg
AND shzet IN s_shzet
AND fabkz IN s_fabkz
AND shpro IN s_shpro
AND eislo IN s_eislo
AND zzfdwe IN s_zzfdwe
AND zzfdwi IN s_zzfdwi
AND zzsspe IN s_zzsspe
AND zzsspi IN s_zzsspi.
IF sy-subrc EQ 0.
SORT i_marc BY matnr werks.
ENDIF.
DELETE ADJACENT DUPLICATES FROM i_marc comparing matnr werks.
*fetching data from mara data base table
IF NOT i_marc[] IS INITIAL.
SELECT matnr lvorm matkl
meins spart prdha
FROM mara INTO TABLE i_mara
FOR ALL ENTRIES IN i_marc
WHERE matnr = i_marc-matnr
AND lvorm IN sp$00094
AND matkl IN sp$00084
AND meins IN sp$00091
AND prdha IN sp$00066
AND spart IN sp$00085.
ENDIF.
IF sy-subrc EQ 0.
SORT i_mara BY matnr.
ENDIF.
DELETE ADJACENT DUPLICATES FROM i_mara comparing matnr.
*fetching data from mbew data base table
IF NOT i_mara[] IS INITIAL.
SELECT matnr bwkey bwtar lbkum
salk3 stprs peinh bklas
FROM mbew INTO TABLE i_mbew
FOR ALL ENTRIES IN i_marc
WHERE matnr = i_marc-matnr
AND bwkey = i_marc-werks
AND bklas IN sp$00063
AND lbkum IN sp$00088.
ENDIF.
IF sy-subrc EQ 0.
SORT i_mbew BY matnr bwkey bwtar.
ENDIF.
*DELETE ADJACENT DUPLICATES FROM i_mbew comparing matnr bwkey bwtar.
*fetching data from makt data base table
IF NOT i_mara[] IS INITIAL.
SELECT matnr spras maktx
FROM makt INTO TABLE i_makt
FOR ALL ENTRIES IN i_mara
WHERE matnr = i_mara-matnr
AND maktx IN sp$00059
AND makt~spras = c_en.
ENDIF.
IF sy-subrc EQ 0.
SORT i_makt BY matnr spras.
ENDIF.
DELETE ADJACENT DUPLICATES FROM i_makt.
*fetching data from cpec data base table
IF NOT i_marc[] IS INITIAL.
SELECT prctr datbi kokrs abtei
FROM cepc INTO TABLE i_cepc
FOR ALL ENTRIES IN i_marc
WHERE prctr = i_marc-prctr
AND prctr IN sp$00087
AND datbi >= sy-datum.
ENDIF.
IF sy-subrc EQ 0.
SORT i_cepc BY prctr datbi kokrs.
ENDIF.
*DELETE ADJACENT DUPLICATES FROM i_cepc.
LOOP AT i_cepc INTO wa_cpec.
read table i_marc into wa_marc with key
prctr = wa_cpec-prctr binary search.
if sy-subrc = 0.
i_matl-abtei = wa_cpec-abtei.
i_matl-prctr1 = wa_cpec-prctr.
i_matl-ausss = wa_marc-ausss.
i_matl-bearz = wa_marc-bearz.
i_matl-beskz = wa_marc-beskz.
i_matl-bstmi = wa_marc-bstmi.
i_matl-wzeit = wa_marc-wzeit.
i_matl-disgr = wa_marc-disgr.
i_matl-maabc = wa_marc-maabc.
i_matl-dismm = wa_marc-dismm.
i_matl-dispo = wa_marc-dispo.
i_matl-dispr = wa_marc-dispr.
i_matl-dzeit = wa_marc-dzeit.
i_matl-plifz = wa_marc-plifz.
i_matl-disls = wa_marc-disls.
i_matl-bstma = wa_marc-bstma.
i_matl-bstrf = wa_marc-bstrf.
i_matl-basmg = wa_marc-basmg.
i_matl-eisbe = wa_marc-eisbe.
i_matl-fevor = wa_marc-fevor.
i_matl-fxhor = wa_marc-fxhor.
i_matl-lvorm1 = wa_marc-fevor.
i_matl-matnr1 = wa_marc-matnr.
i_matl-mmsta = wa_marc-mmsta.
i_matl-prctr = wa_marc-prctr.
i_matl-sobsl = wa_marc-sobsl.
i_matl-tranz = wa_marc-tranz.
i_matl-werks = wa_marc-werks.
i_matl-xchar = wa_marc-xchar.
i_matl-lgpro = wa_marc-lgpro.
i_matl-fhori = wa_marc-fhori.
i_matl-rgekz = wa_marc-rgekz.
i_matl-schgt = wa_marc-schgt.
i_matl-minbe = wa_marc-minbe.
i_matl-ekgrp = wa_marc-ekgrp.
i_matl-eprio = wa_marc-eprio.
i_matl-kausf = wa_marc-kausf.
i_matl-shflg = wa_marc-shflg.
i_matl-shzet = wa_marc-shzet.
i_matl-fabkz = wa_marc-fabkz.
i_matl-lgrad = wa_marc-lgrad.
i_matl-shpro = wa_marc-shpro.
i_matl-eislo = wa_marc-eislo.
i_matl-rwpro = wa_marc-rwpro.
i_matl-lgfsb = wa_marc-lgfsb.
i_matl-zzfdwe = wa_marc-zzfdwe.
i_matl-zzfdwi = wa_marc-zzfdwi.
i_matl-zzsspe = wa_marc-zzsspe.
i_matl-zzsspi = wa_marc-zzsspi.
endif.
READ TABLE i_mara INTO wa_mara WITH KEY
matnr = wa_marc-matnr binary search.
i_matl-lvorm = wa_mara-lvorm.
i_matl-matkl = wa_mara-matkl.
i_matl-matnr = wa_mara-matnr.
i_matl-meins = wa_mara-meins.
i_matl-prdha = wa_mara-prdha.
i_matl-spart = wa_mara-spart.
READ TABLE i_makt INTO wa_makt WITH KEY
matnr = wa_mara-matnr binary search.
i_matl-matnr3 = wa_makt-matnr.
i_matl-maktx = wa_makt-maktx.
READ TABLE i_mbew INTO wa_mbew WITH KEY
matnr = wa_marc-matnr binary search.
i_matl-bklas = wa_mbew-bklas.
i_matl-bwkey = wa_mbew-bwkey.
i_matl-lbkum = wa_mbew-lbkum.
i_matl-salk3 = wa_mbew-salk3.
i_matl-matnr2 = wa_mbew-matnr.
i_matl-peinh = wa_mbew-peinh.
i_matl-stprs = wa_mbew-stprs.
READ TABLE i_cepc INTO wa_cpec WITH KEY
prctr = wa_marc-prctr.
APPEND i_matl.
CLEAR: wa_cpec, wa_mbew, wa_mara, wa_marc.
ENDLOOP.
Thaks
Waiting your reply.Hi Sasmita,
I think your final loop is the problem. As you are looping through the CEPC internal table, and reading the other tables. For different materials there might be a same profit center, the read table will fetch you only first occurance of the profit center from the mara or marc table.
So loop through either mara or marc table and read the remaining and populate your final internal tables. This might solve your problem.
Regards,
Ramesh Babu S
*Reward points if it is helpful.... -
Hi all,
I have a dought ...related to join and all entries
Which one will be the better as per performance prospective :
1>For all entries
or
2> using inner join condition
i am combining 2 tables ...
but in my where clause is having 6-7 condition if i used inner join concept...
Please let me know thanks for the help...in advance
regards
AmitCheck Re: Multiple Table Join instead of Nested Selects? I wrote a program that compares the performance of a join against for all entries. The join won. But the best thing to do is for you test and compare both methods for your particular situation.
In a select, the most important factor is the use of an index.
Rob -
Inner join with for-all entries
Why is the below inner join-for all entries does not result in expected output ?
REPORT ZTST3 .
tables : ztst1,ztst2 .
* table ztst1 has 4 fields : mandt,ebeln,ebelp,etenr,char4. ; ztst2 has
* 3 fields : mandt,ebeln,ebelp,matnr
*Entries in ztst1
* EBELN EBELP ETERN CHAR4
* 5000000000 00010 0001 abc
* 5000000000 00010 0002 cbd
* 5000000000 00010 0003 efg
*Entries in ztst2
* EBELN EBELP matnr
* 5000000000 00010 matabc
*expected itab after inner join
* EBELN EBELP CHAR4 MAtnr
* 5000000000 00010 abc matabc
* 5000000000 00010 cbd matabc
* 5000000000 00010 efg matabc
data : begin of itab1 occurs 0,
ebeln type ebeln,
ebelp type ebelp,
end of itab1.
data : begin of itab occurs 0,
ebeln type ebeln,
ebelp type ebelp,
char4 type char4,
matnr type matnr,
end of itab.
start-of-selection.
itab1-ebeln = '5000000000'.
itab1-ebelp = '00010'.
append itab1.
select ztst1~ebeln
ztst1~ebelp
ztst1~char4
ztst2~matnr into corresponding fields of table itab
from ztst1 inner join ztst2
on ztst1~ebeln = ztst2~ebeln and
ztst1~ebeln = ztst2~ebelp
for all entries in itab1
where
ztst1~ebeln eq itab1-ebeln and
ztst1~ebelp eq itab1-ebelp .
* why does it return no entries;
break-point.For example in the bellow case
*Entries in ztst1
EBELN EBELP ETERN CHAR4
5000000000 00010 0001 abc
5000000000 00010 0002 cbd
5000000000 00010 0003 efg
5000000002 00020 0003 efg
5000000002 00020 0003 efg
*Entries in ztst2
EBELN EBELP matnr
5000000000 00010 matabc
5000000002 00020 abc
may it will return you 2 records yes, than I think you have under stand the working of u201Cfor all entriesu201D ?
And the following case I think it will work fine.
*Entries in ztst1
key EBELN EBELP ETERN CHAR4
1 5000000000 00010 0001 abc
2 5000000000 00010 0002 cbd
3 5000000000 00010 0003 efg
4 5000000002 00020 0003 efg
5 5000000002 00020 0003 efg
*Entries in ztst2
EBELN EBELP matnr
5000000000 00010 matabc
5000000002 00020 abc
select ztst1~key
ztst1~ebeln
ztst1~ebelp
ztst1~char4
ztst2~matnr into corresponding fields of table itab
from ztst1 inner join ztst2
on ztst1~ebeln = ztst2~ebeln and
ztst1~ebelp = ztst2~ebelp
for all entries in itab1
where
ztst1~ebeln eq itab1-ebeln and
ztst1~ebelp eq itab1-ebelp .
Sorry, I donu2019t have system with me right now and I am sending you with out testing but I am sure that it is working the same way.
Please Reply if any problem
Kind Regards,
Faisal -
Inner Join resulting in many, many duplicates
I ran an Inner Join but it returned many, many duplicates. Any idea why that would occur?
One Answer from a different thread:
Because you may be having improper Join condition what has a One to many or a Many to many relationship between the tables. We do not have the data, and hence cannot comment over it. However, since the original issue is resolved, I suggest you close this thread and ask the question in another thread.
What do I look for to identify an improper join?Please don't start another discussion for the same issue.
Continue on your existing thread where the answers and advice you've already been given can be seen, so that people don't end up giving the same advice you've already had.
Answers on other thread: Inner Join error
Locking this thread -
hi All
how many tables join thu inner join.Hi,
You can join any number of tables as long as join conditions exist between the tables. It is not advisable to use more than 4 tables in join. it results in performance issue.
thanks,
sksingh -
Can we use inner joins with for all entries?
Hi,
Can we use innerjoin on two tables MARA and MAKT against the materials in
the internal table.
If so ,please let me know whether there is performance issue.Because if there is
bad performance issue or something else like thise means,my project manager
wont allow to include.
So can one let me know about this.
Thanks,
BalajiHi Arunkumar,
I think you are not clear.My question is can I use innerjoin with
for all entries.For example below is my code.
SELECT A~MATNR
B~MAKTX
A~MTART
A~MATKL
FROM MARA AS A INNER JOIN MAKT AS B
ON AMATNR = BMATNR
INTO TABLE IT_MARA_MAKT
FOR ALL ENTRIES IN IT_MATNR
WHERE A~MATNR = IT_MATNR-MATNR
AND A~EXTWG = P_EXTWG
AND A~SPART = P_SPART.
Can we use like this for all entries along with innerjoins.
Thanks,
Balaji
Maybe you are looking for
-
Can i buy an iphone or ipod with a credit money from alot of gift cards?
Can i buy an iphone or ipod without a credit card because i have money as credit in my apple account from gift cards so i wonder if i can buy anything beside apps,music....etc ?
-
Any resolution to the sound problem?
I have been having the same sound problem with my Mid 2010 Mac Pro tower ever since I got it. I have been in touch with Apple and have been told that they are familiar with the problem, but that they are still working on a fix. The problem is that
-
Hello Gurus, I am having a small problem while printing the smartform. I wan to display a link in the smart form with tilte. Example Link : www.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.com But it is displaying like
-
How to attach break point at loop statement in smartforms.
-
Every time i try to connect to the internet i get this error message " safari cannot open the page because it is not connected to the internet. I have a vodafone sim card inserted and a linksys wireless router.