Better to have outer join or to have for all entries
Hi Gurus
I have one select query taking lot of time to retrieve data.
My question is Is it better to have a outer join or should i go with For all entries.
SELECT distinct sbukrs skunnr sumskz sgsber sbschl swaers
sblart szfbdt sgjahr sbelnr sbuzei sbudat
swrbtr sdmbtr sshkzg crzzrprctr
APPENDING TABLE gt_data_a
FROM bsad AS s
LEFT OUTER JOIN zcce1a as c
ON sbukrs = crbukrs
AND sgjahr = crefryear
AND sbelnr = cbelnr
AND sbuzei = cbuzei
AND sSHKZG = cDRCRK
AND c~REFDOCCT = 'W'
AND c~RLDNR = 'Z1'
AND c~RVERS = '001'
WHERE
s~bukrs IN s_bukrs
AND s~kunnr IN s_kunnr
AND s~umsks IN s_umsks
AND s~umskz IN s_umskz
AND s~augdt IN s_augdt
AND s~augbl IN s_augbl
AND s~zuonr IN s_zuonr
AND s~gjahr IN s_gjahr1
AND s~belnr IN s_belnr
AND ( sbudat IN s_budat1 AND sbudat LE p_stida )
AND s~augdt GT p_stida
AND s~bldat IN s_bldat1
AND s~cpudt IN s_cpudt
AND s~waers IN s_waers1
AND s~xblnr IN s_xblnr
AND s~blart IN s_blart
AND s~monat IN s_monat
AND s~bschl IN s_bschl
AND s~shkzg IN s_shkzg
AND s~gsber IN s_gsber
AND s~mwskz IN s_mwskz
AND s~dmbtr IN s_dmbtr
AND s~wrbtr IN s_wrbtr
AND s~hkont IN s_hkont
AND s~filkd IN s_filkd
AND s~zlsch IN s_zlsch
AND s~zlspr IN s_zlspr
AND s~mansp IN s_mansp
AND s~mschl IN s_mschl
AND s~madat IN s_madat
AND s~manst IN s_manst
AND s~maber IN s_maber
AND s~rstgr IN s_rstgr
AND s~projk IN s_projk
AND s~xref1 IN s_xref1
AND s~xref2 IN s_xref2
AND s~imkey IN s_imkey
AND s~fistl IN s_fistl
AND s~dabrz IN s_dabrz
AND s~kostl IN s_kostl
AND s~cession_kz IN s_cessio.
Moderator message - Please see Please Read before Posting in the Performance and Tuning Forum before posting - post locked
Edited by: Rob Burbank on Sep 15, 2009 9:52 AM
Hi Sandeep Sharma,
Table BSAD is having below primary key fields...
BUKRS
KUNNR
UMSKS
UMSKZ
AUGDT
AUGBL
ZUONR
GJAHR
BELNR
BUZEI
Now the Question is In your selection screen what and all fields you kept mandatory ??
Try to make some of these above fileds as mandatory which may fit one of the index of BSAD table...
Different Available Indexes on BSAD is as below...
Index for logical database
MANDT
KUNNR
BUKRS
AUGDT
AUGBL
GJAHR
BELNR
BUZEI
Index using settlement run (payment cards)
MANDT
BUKRS
CCBTC
Index for Invoice Reference
MANDT
BUKRS
REBZG
REBZJ
REBZZ
KUNNR
UMSKS
REBZT
Index for Line Item Access
MANDT
BUKRS
BELNR
GJAHR
BUZEI
Index for BW Extract
MANDT
BUKRS
CPUDT
Also code in both the way... and check the time of execution for the queries... Actually it(Performance) depends on data as well as selection criteria...
Hope it will solve your problem..
Thanks & Regards
ilesh 24x7
ilesh Nandaniya
Similar Messages
-
Join table SUM using for all entries
Dear All,
Will anyone pls. tell me what is the problem in this query, it is not working.
SELECT aufnr SUM( menge )
INTO CORRESPONDING FIELDS OF TABLE itab_aufnr
FROM mkpf
INNER JOIN mseg ON msegmblnr EQ mkpfmblnr AND mkpfmjahr EQ msegmjahr
FOR ALL ENTRIES IN itab_rework
WHERE mseg~aufnr = itab_rework-aufnr
GROUP BY aufnr.
Regards,
Moderator message: please search for available information before asking, "it's not working" is not a proper error description.
Edited by: Thomas Zloch on Dec 6, 2010 9:41 AMWhen I have used it in loop it is taking so much time to execute.
That depends upon the amount of data you are processing and the set of codes written inside the loop. For sum you have to use collect statement or a SUM statement inside a control break statement. -
Join 3 tables using FOR ALL ENTRIES
Hi,
I want to join 3 tables and show their result in a text file delimited by comma.
ITs a download program.Can someone tell me how to how to join the three table using for all entires instead of inner join.please give step by step illustrationHi,
Please check below code which downloads records from 3 tables into excel file.
if you want other file means you can specify other file type in the fm parameter
REPORT zstemp_qty2_ LINE-SIZE 255 .
DATA:it_vbak LIKE vbak OCCURS 0 WITH HEADER LINE.
DATA:v_file1 LIKE rlgrap-filename.
DATA:v_file2(80) TYPE c.
DATA:it_vbap LIKE vbap OCCURS 0 WITH HEADER LINE.
DATA:it_mara LIKE mara OCCURS 0 WITH HEADER LINE.
START-OF-SELECTION.
SELECT * FROM vbak INTO TABLE it_vbak UP TO 100 ROWS.
IF NOT it_vbak[] IS INITIAL.
SELECT * FROM vbap INTO TABLE it_vbap
FOR ALL ENTRIES IN it_vbak
WHERE vbeln = it_vbak-vbeln.
ENDIF.
LOOP AT it_vbap.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = it_vbap-matnr
IMPORTING
output = it_vbap-matnr.
MODIFY it_vbap TRANSPORTING matnr.CLEAR it_vbap.
ENDLOOP.
IF NOT it_vbap[] IS INITIAL.
SELECT * FROM mara INTO TABLE it_mara
FOR ALL ENTRIES IN it_vbap
WHERE matnr = it_vbap-matnr.
ENDIF.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = sy-cprog
dynpro_number = sy-dynnr
FIELD_NAME = ' '
IMPORTING
file_name = v_file1 .
v_file2 = v_file1.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
BIN_FILESIZE = ' '
CODEPAGE = ' '
filename = v_file2
filetype = 'WK1'
MODE = ' '
WK1_N_FORMAT = ' '
WK1_N_SIZE = ' '
WK1_T_FORMAT = ' '
WK1_T_SIZE = ' '
col_select = '1'
COL_SELECTMASK = ' '
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH =
TABLES
data_tab = it_mara
FIELDNAMES =
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_WRITE_ERROR = 2
INVALID_FILESIZE = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
OTHERS = 10
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT it_mara.
WRITE:/ it_mara-matnr.
ENDLOOP.
Regds
Sivaparvathi
Please reward points if helpful..... -
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 -
I have a problem in using for all entries
Hi i have a problem in using <b>for all entries</b>
i have declared the two internal tables as below
DATA: BEGIN OF ITAB OCCURS 10,
EBELN LIKE EKKO-EBELN,
LIFNR LIKE EKKO-LIFNR,
EBELP LIKE EKBE-EBELP,
BELNR LIKE EKBE-BELNR,
* MATNR LIKE EKPO-MATNR,
* TXZ01 LIKE EKPO-TXZ01,
VGABE LIKE EKBE-VGABE,
GJAHR LIKE EKBE-GJAHR,
KNUMV LIKE EKKO-KNUMV,
END OF ITAB.
DATA: BEGIN OF ITAB1 OCCURS 10,
EBELN LIKE EKPO-EBELN,
MATNR LIKE EKPO-MATNR,
TXZ01 LIKE EKPO-TXZ01,
WERKS LIKE EKPO-WERKS,
NETWR LIKE EKPO-NETWR,
MENGE LIKE EKPO-MENGE,
MWSKZ LIKE EKPO-MWSKZ,
LIFNR LIKE EKKO-LIFNR,
EBELP LIKE EKBE-EBELP,
BELNR LIKE EKBE-BELNR,
END OF ITAB1.
<b>and now i have tried to move the values in those internal tables using these statements</b>
SELECT A~EBELN A~LIFNR A~KNUMV B~VGABE B~EBELP B~GJAHR B~BELNR
FROM EKKO AS A
INNER JOIN EKBE AS B ON B~EBELN = A~EBELN
INTO CORRESPONDING
FIELDS OF TABLE ITAB WHERE B~VGABE = '2'.
SELECT EKPO~EBELN EKPO~MATNR EKPO~TXZ01 EKPO~WERKS EKPO~NETWR
EKPO~MENGE EKPO~MWSKZ
FROM EKPO
INTO CORRESPONDING FIELDS OF TABLE ITAB1
FOR ALL ENTRIES IN ITAB
WHERE EBELN = ITAB-EBELN.
LOOP AT ITAB1.
READ TABLE ITAB WITH KEY EBELN = ITAB-EBELN.
ITAB-EBELN = ITAB1-EBELN.
ITAB1-LIFNR = ITAB-LIFNR.
ITAB1-EBELP = ITAB-EBELP.
ITAB1-BELNR = ITAB-BELNR.
ITAB1-EBELP = ITAB-EBELP.
APPEND ITAB1.
ENDLOOP.
But when i was using loop then it was displaying values in debugging mode but while i was trying to execute it was taking a lot of time i thought that it was due to more information in the already declared internal table so i have tried to remove the previous entries but it was showing an error while i was removing the old entries
and when i remove the loop at itab1 then i'll get output directly but it was displaying the itab fields which is my 1st internal table but not the values of itab1 can u explain me what is the possible error for that
Regards ,
Pavanbefore using for all entries in, u need to check whether the driver internal table is empty, if it is empty, u should not enter into select statement.
if u wont use this check means, when the driver internal table is empty, the second select will take all the entires from the tables.
SELECT AEBELN ALIFNR AKNUMV BVGABE BEBELP BGJAHR B~BELNR
FROM EKKO AS A
INNER JOIN EKBE AS B ON BEBELN = AEBELN
INTO CORRESPONDING
FIELDS OF TABLE ITAB WHERE B~VGABE = '2'.
if itab[] is not initial.
SELECT EKPOEBELN EKPOMATNR EKPOTXZ01 EKPOWERKS EKPO~NETWR
EKPOMENGE EKPOMWSKZ
FROM EKPO
INTO CORRESPONDING FIELDS OF TABLE ITAB1
FOR ALL ENTRIES IN ITAB
WHERE EBELN = ITAB-EBELN.
endif.
I hope this will help u.
else,
Sujatha. -
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. -
I have just joined creative cloud just for Photoshop but it will not download?
I have just joined creative cloud just for Photoshop but it will not download?
We cannot know. Even calling your post would be an exaggeration/ understatement, depending on how you want to see it. We need hard technical facts - operating system, computer specs, what is the exact error/ problem and so on.
Mylenium -
For all entries from 2 tables that have no common key
Hello
I have the next querry that i want to write in abap
AUFK -
>aufk-aufnr = afko- aufnr----> AFKO
AUFK---->aufk-pspel = afvc-projn -
>AFVC
AFKO-----> afko-rsnum = resb-rsnum -
> RESB
AFVC-----> afvc-aufpl = resb-aufpl -
> RESB
AFVC-----> afvc-vornr = resb-vornr -
> RESB
So that i have to start with AUFK and from there i read AFKO and AFVC and with the entries from AFKO and AFVC i have to do a select on RESB.
How can i do this
select from RESB
for all entries in AFKO
where ...
for all entries in AFVC
where... ?
I do not have any common key between AFVC and AFKO. How can i select the correct entries from RESB?
I have to mention that i have 1-1 entries for AUFK and AFKO
and 1-N entries for AUFK and AFVC
Thank youWhy don't you use afko-aufpl = afvc-aufpl ?
Regards,
Raymond -
Why Inner join or Outer join is not used for Pool or Cluster tables ?
Hi SAP-ABAP Experts .
With Due Regards .
May u explain me why Inner join or Outer join is not useful for Pool or Cluster tables ?
because peoples advised not use Joins for Pool and Cluster tables , What harm will take place , If we do this ?
Best Regards to all : RajneeshBoth Pooled and Cluster Tables are stored as tables within the database. Only the structures of the two table types which represent a single logical view of the data are defined within the ABAP/4 Data Dictionary. The data is actually stored in bulk storage in a different structure. These tables are commonly loaded into memory (i.e., 'buffered') due to the fact they are typically used for storing internal control information and other types of data with little or no external (business) relevance.
Pooled and cluster tables are usually used only by SAP and not used by customers, probably because of the proprietary format of these tables within the database and because of technical restrictions placed upon their use within ABAP/4 programs. On a pooled or cluster table:
Secondary indexes cannot be created.
You cannot use the ABAP/4 constructs select distinct or group by.
You cannot use native SQL.
You cannot specify field names after the order by clause. order by primary key is the only permitted variation.
I hope it helps.
Best Regards,
Vibha
Please mark all the helpful answers -
Left outer join using For All Entries
how to implement left outer join using for all entries In REPORTS.
hi Mansi,
this is how i populate
SELECT VGBEL LFIMG POSNR VBELN FROM LIPS INTO TABLE IT_delv FOR ALL ENTRIES IN IT_VBAP WHERE VGBEL = IT_VBAP-VBELN.
LOOP AT IT_delv INTO WA_delv.
WA_FINAL-VBELN_1 = WA_DELV-VBELN_1.
WA_FINAL-LFDAT = WA_DELV-LFDAT.
WA_FINAL-LFIMG = WA_DELV-LFIMG.
WA_FINAL-POSNR2 = WA_DELV-POSNR2..
APPEND WA_FINAL TO IT_FINAL.
CLEAR: WA_FINAL , WA_delv.
ENDLOOP.
LOOP AT IT_FINAL INTO WA_FINAL.
READ TABLE IT_vbap INTO WA_vbap WITH KEY VGBEL = WA_FINAL-VBELN.
WA_FINAL-VBELN = WA_VBAP-VBELN.
WA_FINAL-MATNR = WA_VBAP-MATNR.
WA_FINAL-KWMENG = WA_VBAP-KWMENG.
WA_FINAL-NETWR = WA_VBAP-NETWR.
MODIFY IT_FINAL FROM WA_FINAL.
ENDLOOP.
My question is , it_vbap has 5 five records A,B,C,D,E.
in it_delv ,there are 20 record corrresponding to A,B,D of IT_VBAP.
in final table i wont get info of recors B,E. I want those info also in final table ..how can i do that... -
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. -
Inner join Vs for all entries for performance
hi,
i need to fetch data from 5 tables where i have common key vbeln, is this suggestable to write a select query with inner join or write an inner join for 2 tables with more fileds and for remaining using for all entries.... please suggest how can i increase the performance...all points are rewarded....
thnaks alot.Is this a dialog program or a data extract? Rob is right in that the difference is negligible IF the number of records involved are only a few.
On the other hand, if you are extracting a large number of records, then the performance depends on a number of things and is generally unpredictable.
The way I approach it is by first developing the extract program with a join because it is easier to code. If the program run time is within the acceptable range, I would let it be and migrate to production. If the performance is of high priority and if the join appears to take long time, then I will comment out the code and try the FAE approach. If the run time with FAE is not markedly better, then I would go back to join. -
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. -
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
Maybe you are looking for
-
Hi there! Sorry if this has been answered before, but the forum search ignores '%' so I could not find anything relevant. I'm completely at a loss here guys so any help will be really appreciated. I've got a database adapter that executes a "pure SQL
-
Hello, Are there any reporting options for GR/IR. SPecifically a report that shows all items that have been cleared? Thanks, Justin
-
No risk at using APC Back UPS RS1500 :-)
I recently posted this question... See thread http://discussions.apple.com/message.jspa?messageID=3243602#3243602 The technician at APC informed me that if I have a 2006 Mac the problem is solved and can use the RS 1500 without any risk. I had also a
-
Standard Templates on Project Schedule & GO LIVE SIGN OFF document?
Hi It would be really helpful if someone could provide me a Standard Template for "PROJECT SCHEDULE" and "GO LIVE SIGN OFF document. Its very urgent. I would be really appreciate if you could send it over to [email protected] Thanks in advance, Sande
-
Error Code 80073712 after Windows update.
I have yet another error code when Windows issued yet another automatic update. This time it is #80073712. I have gotten so many of these now, as Windows automatic updates download but fail to install. Might this be because I am using Mozilla Fire