Query is too slow from bseg selection
SELECT BELNR BLDAT BUDAT XBLNR GJAHR tcode WAERS AWKEY FROM BKPF INTO
TABLE
ITBKPF WHERE BUKRS EQ P_BUKRS AND BELNR IN S_BELNR AND BUDAT IN
P_BUDAT
AND STBLG = ''
AND ( TCODE = 'MIRO' OR
TCODE = 'MR8M' OR
TCODE = 'MB11' OR
TCODE = 'MB1B' OR
TCODE = 'MIGO_GI' OR
TCODE = 'MIGO_TR' OR
TCODE = 'MB1A' ).
IF SY-SUBRC EQ 0.
SORT itBKPF.
ELSE.
MESSAGE 'No data for the relevant date' TYPE 'A'.
LEAVE LIST-PROCESSING.
ENDIF.
SELECT A1LIFNR A1NAME1 A1ORT01 A1STRAS B1~j_1icstno
INTO TABLE it_werks
FROM ( LFA1 AS A1 INNER JOIN j_1imocomp AS B1 ON A1werks = B1werks )
**********************************************this is too slow*************
SELECT BUKRS BELNR GJAHR BUZEI BUZID BSCHL SHKZG GSBER MWSKZ
DMBTR HKONT LIFNR LANDL Matnr werks MENGE EBELP xref3
INTO CORRESPONDING FIELDS OF TABLE ITABBSEG
FROM BSEG
FOR ALL ENTRIES IN ITBKPF
WHERE BELNR = ITBKPF-BELNR
AND GJAHR = ITBKPF-GJAHR
AND ( BSCHL = '86' OR BSCHL = '96' or BSCHL = '89' OR BSCHL = '99' )
AND WERKS IN S_WERKS
AND BUZID <> 'F' .
****************************************this is too slow
Moderator message: Please Read before Posting in the Performance and Tuning Forum
locked by: Thomas Zloch on Aug 5, 2010 2:08 PM
You should have provided the full key of the cluster file behind BSEG (RFBLG), every key is in BKPF, so add BUKRS
SELECT bukrs belnr gjahr buzei buzid bschl shkzg gsber mwskz
dmbtr hkont lifnr landl matnr werks menge ebelp xref3
INTO CORRESPONDING FIELDS OF TABLE itabbseg
FROM bseg
FOR ALL ENTRIES IN itbkpf
WHERE bukrs = itbkpf-bukrs
AND belnr = itbkpf-belnr
AND gjahr = itbkpf-gjahr
AND ( bschl EQ '86' OR bschl EQ '96' OR bschl EQ '89' OR bschl EQ '99' )
AND werks IN s_werks
AND buzid EQ 'F' .
You could also extract the whole accounting document in the internal table, and then delete record using the not-database-key selections.
SELECT bukrs belnr gjahr buzei buzid bschl shkzg gsber mwskz
dmbtr hkont lifnr landl matnr werks menge ebelp xref3
INTO CORRESPONDING FIELDS OF TABLE itabbseg
FROM bseg
FOR ALL ENTRIES IN itbkpf
WHERE bukrs = itbkpf-bukrs
AND belnr = itbkpf-belnr
AND gjahr = itbkpf-gjahr.
DELETE itabbseg WHERE
( bschl NE '86' AND bschl NE '96' AND bschl NE '89' AND bschl NE '99' )
OR NOT ( werks IN s_werks )
OR BUZID NE 'F' .
In both case, perform some tests with tools like SE30 or ST05.
Regards,
Raymond
Similar Messages
-
Hi,
I never read data from Cluster table like BSEG, is there any precautions to be taken while reading data from it? as it contains voluminous data
please suggest.
regards,
Pra<b>Cluster Tables (BSEG,BSEC)</b>
Should be accessed via primary key - very fast retrieval otherwise very slow
No secondary indexes
Select * is Ok because all columns retrieved anyway. Performing an operation on multiple rows is more efficient than single row operations. Therefore you still want to select into an internal table. If many rows are being selected into the internal table, you might still like to retrieve specific columns to cut down on the memory required.
Statistical SQL functions (SUM, AVG, MIN, MAX, etc) not supported
Can not be buffered
SELECT bukrs belnr gjahr blart budat monat
tcode bvorg waers kursf hwaer
FROM bkpf
INTO TABLE it_bkpf
WHERE bukrs IN s_bukrs
AND gjahr IN s_gjahr
AND monat IN s_monat
AND tcode IN ('CO88', 'KO88', 'KK87')
AND awtyp EQ c_ref_pro. "'AUAK'
Pick up the corresponding line items from BSEG
SELECT bukrs belnr gjahr dmbtr wrbtr ktosl
zuonr hkont matnr werks menge
FROM bseg
INTO TABLE it_bseg
FOR ALL ENTRIES IN it_bkpf
WHERE bukrs = it_bkpf-bukrs
AND belnr = it_bkpf-belnr
AND gjahr = it_bkpf-gjahr
AND werks IN s_werks
AND ktosl = c_tr_key. "'PRD'
<b>BSEG Access</b>
BSAD Accounting: Secondary index for customers (cleared items)
BSAK Accounting: Secondary index for vendors (cleared items)
BSAS Accounting: Secondary index for G/L accounts (cleared items)
BSID Accounting: Secondary index for customers
BSIK Accounting: Secondary index for vendors
BSIM Secondary Index, Documents for Material
BSIS Accounting: Secondary index for G/L accounts -
New Satellite C50-A264 Laptop way too slow.
I got this Satellite C50-A254 few weeks ago,i didnt touch it alot.
I only used this laptop 2-3 times but its just terribly slow.
Even if i launched Google Chrome,it constantly stopps responding and i have no idea why because it was too slow from the first place when i booted this laptop which doesnt make sence at all.
I cant run literary anything good. Even opening control panel takes about 5 seconds.
The specs are:
OS: Windows 8
HDD: 500GB
RAM: 2GB
CPU: Pentunum
I've only installed uTorrent and Steam,but i dont know why that causes this laptop to be terriblely slow.
I didnt tried to uninstall anything since it was slow from the first time.
I'm sure this was not a re-used PC.I have the exact same stituation with the Toshiba C50D
Bought it from the South African disributor
Out of the box it was so slow as to be unuseable even for basic email
within 2 days I took it back
They would not accept it back as it has been used (tried once and not again.)
I am now stuck with the WORST EVER COMPUTER, WHICH HAS TOTALLY PUT ME OFF ALL TOSHIBA PRODUCTS.
The computer has lived in the cupboard in it's box for the past 6 months and not been used.
I have since purchased a DELL in the same price range for my wife.
I have since purchased a much more expensive Acer as a work machine.
===============
Out of curiosity in the last day - I intalled a 256 Gig Solid state drive and increased the memory to 8Gig. Updated to Windows 8.1
ABSOLUTELY NO CHANGE IN THE POOR PERFORMANCE.
SHAME ON YOU TOSHIBA FOR SELLING SUCH COMPLETE RUBBISH AND RIPPING THE PUBLIC OFF.
I can be reached on timo (a) clavitech.com -
Select Data from aufm too slow
Hi experts,
I have a query in my report but its performance too slow.
is there any proper way or any way to improve the performance of below query.
SELECT * FROM aufm into table i_aufm " collecting input material document numbers
WHERE mblnr GE '4900000000'
AND mjahr GE '2008'
AND zeile GT '0'
AND matnr EQ matnr_101-matnr
AND werks IN p_werks
AND charg EQ matnr_101-charg
AND bwart = '101'.Hi,
1 .Dont use * from any table.
2. Create a internal table that u want to retrieve the data from that table. (Structure).
Eg:
types : begin of str_ekko,
ebeln type ekko-ebeln,
bsart type ekko-bsart,
aedat type ekko-aedat,
endof str_ekko.
data : itab type table of str_ekko,
wa_itab type str_ekko.
In the above u want to take care that while creating the structure u want to look the sequence of fields in the table. in the same sequence u want to create the structure.
3 . The Select-options fields also wants be in the same field sequence of the table.
eg : select ebeln bsart aedat from ekko into table itab where ebeln in so_ebeln and
bsart in so_bsart and
aedat in so_aedat.
4. If the above things are not working just look the indexes of that table. Just create a secondary index with ur requirement. -
Abap query to select a line item # from bseg on basis of following pattern:
Hello,
I want to retrieve the line item # from bseg which has the following pattern,
account type = S
AND
gl account starting from 135***** , 136***** , 137*****
, 138***** , 139*****
hope i am comprehendable. How do i go on writing the query,
Thanks..
ShehryarHi Shehryar,
This will fetch records with GL A/C starting with <b>13</b> only , if you want 14 and others also write sepearate conditions using <b>LIKE</b> statements.
REPORT zztest.
DATA : itab TYPE STANDARD TABLE OF bseg WITH HEADER LINE.
SELECT * FROM bseg INTO TABLE itab WHERE <b>koart = 'S'
AND
hkont LIKE '13%'</b>.
This will take a lot of DB time for fetching the records, try to include Key Fields(BUKRS and GJAHR .. if possible others).
Regards,
Arun Sambargi.
Regards -
Select query taking too much time to fetch data from pool table a005
Dear all,
I am using 2 pool table a005 and a006 in my program. I am using select query to fetch data from these table. i.e. example is mentioned below.
select * from a005 into table t_a005 for all entries in it_itab
where vkorg in s_vkorg
and matnr in s_matnr
and aplp in s_aplp
and kmunh = it_itab-kmunh.
here i can't create index also as tables are pool table...If there is any solutions , than please help me for same..
Thanks ,it would be helpful to know what other fields are in the internal table you are using for the FOR ALL ENTRIES.
In general, you should code the order of your fields in the select in the same order as they appear in the database. If you do not have the top key field, then the entire database is read. If it's large then it's going to take a lot of time. The more key fields from the beginning of the structure that you can supply at faster the retrieval.
Regards,
Brent -
How to fetch data from bseg based on 2 internal tables in 1 select query?
hi,
i have bukrs and belnr in one internal table and bukrs and vbeln in another internal table..now if i select from bseg twice using for all entries for fields bukrs vbeln and bukrs belnr twice in 2 select statements its fine..but since bseg is a huge table i want to use select only once..but the problem is that none of the belnrs in the one internal table will have vbeln in another internal table....ie if vbeln is selected from bseg based on belnr in 1 internal table non eof those vbeln will be equal to vbeln on another internal tables..in this scenario even if i take all data from two internal tables into 1 single internal table and then use for all entries on vbeln and belnr of that table ..but i think this will not work because and AND operator will not work because no record will satisfy both vbeln and belnr conditions..even if i use OR operator if the 1st condition satisfies the select clause will not enter into the second clause and all the records will not be fetched...Please help how should i tackle this..Hi vijaya,
no simple select statement solution so far.
As BSEG is a huge table you should try to get the full key values into another internal table first.
SAP avoids direct selections from BSEG.
Pleas consider the use of one of the secondary index tables first:
BSAD : Accounting: Secondary Index for Customers (Cleared Items)
BSAK : Accounting: Secondary Index for Vendors (Cleared Items)
BSAS : Accounting: Secondary Index for G/L Accounts (Cleared Item
BSEC : One-Time Account Data Document Segment
BSEG : Accounting Document Segment
BSID : Accounting: Secondary Index for Customers
BSIK : Accounting: Secondary Index for Vendors
BSIS : Accounting: Secondary Index for G/L Accounts
you may include
BKPF : Accounting Document Header
for restrictions about time and document type.
The last step is a FOR ALL ENTRIES selection from BSEG providing the full key values.
Although you may have even more selects, the overall performance will be much better.
Regards,
Clemens -
Good day master's!
I'm having a so slow query with this code:
SELECT EBELN BELNR AUGBL GJAHR KOSTL INTO TABLE IT_BSEG FROM BSEG WHERE EBELN EQ LS_EKKO-EBELN AND BUKRS EQ S_BUKRS.
I use ABAP debugger and found out the cause why my program are so slow. Reading the BSEG table take a while to read. Is there alternate way to use.
Thanks, Sorry for my bad english.Hi Kenneth,
Please try this
TYPES: BEGIN OF TY_RSEG,
BELNR TYPE RSEG-BELNR,
GJAHR TYPE RSEG-GJAHR,
EBELN TYPE RSEG-EBELN,
EBELP TYPE RSEG-EBELP,
AWKEY TYPE BKPF-AWKEY,
END OF TY_RSEG.
TYPES: BEGIN OF TY_BKPF,
BUKRS TYPE BKPF-BUKRS,
BELNR TYPE BKPF-BELNR,
GJAHR TYPE BKPF-GJAHR,
AWKEY TYPE BKPF-AWKEY,
END OF TY_BKPF.
DATA: IT_RSEG TYPE TABLE OF TY_RSEG,
IT_BKPF TYPE TABLE OF TY_BKPF.
FIELD-SYMBOLS : <FS_RSEG> TYPE TY_RSEG.
SELECT BELNR GJAHR EBELN EBELP FROM RSEG INTO CORRESPONDING FIELDS OF TABLE IT_RSEG
WHERE EBELN IN S_EBELN.
LOOP AT IT_RSEG ASSIGNING <FS_RSEG>.
<FS_RSEG>-AWKEY+0(10) = <FS_RSEG>-BELNR.
<FS_RSEG>-AWKEY+10(4) = <FS_RSEG>-GJAHR.
ENDLOOP.
IF IT_RSEG[] IS NOT INITIAL.
SELECT BUKRS BELNR GJAHR AWKEY FROM BKPF INTO TABLE IT_BKPF FOR ALL ENTRIES IN IT_RSEG
WHERE AWKEY = IT_RSEG-AWKEY.
ENDIF.
IF IT_BKPF[] IS NOT INITIAL.
SELECT * FROM BSEG INTO TABLE IT_BSEG FOR ALL ENTRIES IN IT_BKPF
WHERE BUKRS = IT_BKPF-BUKRS
AND BELNR = IT_BKPF-BELNR
AND GJAHR = IT_BKPF-GJAHR.
ENDIF.
I Think , it is helpful.
Regards,
Nilesh Patel -
Problem while selecting BELNR from BSEG
Hi Experts,
I have a report performance problem while fetching BELNR from BSEG table.
I have to print latest BELNR from BSEG where BUZID = M but at the time of execution of report, It is taking too much time (More that hour and sometimes it gets hanged).
I have also gone through the comments provided by experts for previous problems asked in this forum e.g. BSEG is a cluster table that is why data retrieval takes long time etc.
Can any one has any other idea or suggestion or any other way to solve this problem
Regards,
NeerajHi,
1) Try to create an index on BUZID field
2) Don't use SELECT/ENDSELECT statement. Instead of that extract all the concerned entries from BSEG into an internal table :
select belnr from bseg appending table itab where buzid = 'M'.
then do this :
sort itab by belnr.
describe itab lines n.
read table itab index n.
Please reward if helpful.
Regards,
Nicolas. -
Data from Bseg taking too much time
Hi ,
I need to extract data from BSEG and it is goin in timeout.
my query is :
1 : on the basis of VBRK i need to fetch data from bseg.
loop at it_vbrk.
awkk = it_vbrk-vbeln.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = awkk
IMPORTING
output = awkk.
it_awkey-vbeln = it_vbrk-vbeln.
it_awkey-awkey = awkk.
append it_awkey.
endloop.
2.
if it_awkey[] is not initial.
select bukrs BELNR gjahr BLART AWKEY from bkpf into table it_bkpf for all entries in it_awkey
where
bukrs = '5000'
and blart EQ 'RV'
and awkey = it_awkey-awkey.
endif.
Please guide me to get solution
Ashish GautamOk, u can use the secondary index tables of BSEG...
BSAS
BSIS,
BSAD,
BSID,
BSAK,
BSIK,
BSIM.
whatever is in BSEG is also in these tables....
and if u use BSEG, then try to match the key fields of BSEG, then only it will give the best performance....
eg.
BUKRS
BELNR
GJAHR
BUZEI
use the same order as given in the database...
and do not use any other fields except the key fields in the where clause...
and do not use 'NE' 'Not in' in the where clause....
regards
Sukriti.... -
Performance problem with selecting records from BSEG and KONV
Hi,
I am having performance problem while selecting records from BSEG and KONV table. As these two tables have large amount of data , they are taking lot of time . Can anyone help me in improving the performance . Thanks in advance .
Regards,
PrashantHi,
Some steps to improve performance
SOME STEPS USED TO IMPROVE UR PERFORMANCE:
1. Avoid using SELECT...ENDSELECT... construct and use SELECT ... INTO TABLE.
2. Use WHERE clause in your SELECT statement to restrict the volume of data retrieved.
3. Design your Query to Use as much index fields as possible from left to right in your WHERE statement
4. Use FOR ALL ENTRIES in your SELECT statement to retrieve the matching records at one shot.
5. Avoid using nested SELECT statement SELECT within LOOPs.
6. Avoid using INTO CORRESPONDING FIELDS OF TABLE. Instead use INTO TABLE.
7. Avoid using SELECT * and Select only the required fields from the table.
8. Avoid nested loops when working with large internal tables.
9. Use assign instead of into in LOOPs for table types with large work areas
10. When in doubt call transaction SE30 and use the examples and check your code
11. Whenever using READ TABLE use BINARY SEARCH addition to speed up the search. Be sure to sort the internal table before binary search. This is a general thumb rule but typically if you are sure that the data in internal table is less than 200 entries you need not do SORT and use BINARY SEARCH since this is an overhead in performance.
12. Use "CHECK" instead of IF/ENDIF whenever possible.
13. Use "CASE" instead of IF/ENDIF whenever possible.
14. Use "MOVE" with individual variable/field moves instead of "MOVE-
CORRESPONDING" creates more coding but is more effcient. -
Why is the select Count too slow
I am doing the following select count and calling it from my JSP to get the total number of records... why is it so slow...
select count(*)
from
(select distinct o.receive_id, o.name, o.address
from order o, item i
where o.id = i.id
and o.status = 2 and i.status = 0)If the data in the table that you are referring to in the query gets refreshed very often and your high water mark on your table not reset, then this query always runs longer. While deleting data in the table, use 'TRUNCATE' rather than 'DELETE' in your data queries. that would help reset the high water mark and your count() queries will run very very fast.
-
Delete too slow, need selective truncate...
We are trying to delete approx 60,000 rows from a wide table. Using the delete command with proper indexes is still too slow.
Unfortunately there is still more data that needs to remain there, so a truncate will no work. Ideally I am looking for a way of doing a selective truncate.
Habing the selectiveness of using the delete command, but bypassing the rollback segment like the truncate command.
Any help would be greatly appreciated,
please email me with your thoughts and comments.
[email protected]Please excuse the crappy punctuation, I cut this out of a pdf document on the web. You may be able to partition along delete lines and then truncate a partition as suggested below.
Gool Luck, Kevin
In Oracl e8 there are some new options avail abl e in the ALTER TABLE statement
that al l ow you to perform maintenance on t he partitions. With these options
yo u c an ADD, MOVE, DROP, TRUNCATE, and SPLIT partitions.
null -
Hi all
In one of my program i have to use selection from BSEG by using non key fields like anln1, hkont etc.
My program run time taking too much time i.e 1.5 to 2hrs
Is there any criteria to reduce my run time.
plz help
thks
sateeshHi
If you need a select by field hkont (so G/L account) use the table BSIS (open item) and BSAS (cleared item) instead of BSEG, just Eric said.
SELECT * FROM BSAS WHERE BUKRS = BUKRS
AND HKONT = HKONT.
SELECT SINGLE * FROM BSEG WHERE BUKRS = BSAS-BUKRS
AND BELNR = BSAS-BELNR
AND GJAHR = BSAS-GJAHR
AND BUZEI = BSAS-BUZEI.
SELECT SINGLE * FROM BKPF WHERE BUKRS = BSAS-BUKRS
AND BELNR = BSAS-BELNR
AND GJAHR = BSAS-GJAH.
Max
Edited by: max bianchi on Nov 5, 2008 11:03 AM -
How can i update rows in a table based on a match from a select query
Hello
How can i update rows in a table based on a match from a select query fron two other tables with a update using sqlplus ?
Thanks Glenn
table1
attribute1 varchar2 (10)
attribute2 varchar2 (10)
processed varchar2 (10)
table2
attribute1 varchar2 (10)
table3
attribute2 varchar2 (10)
An example:
set table1.processed = "Y"
where (table1.attribute1 = table2.attribute1)
and (table1.attribute2 = table3.attribute2)Hi,
Etbin wrote:
Hi, Frank
taking nulls into account, what if some attributes are null ;) then the query should look like
NOT TESTED !
update table1 t1
set processed = 'Y'
where exists(select null
from table2
where lnnvl(attribute1 != t1.attribute1)
and exists(select null
from table3
where lnnvl(attribute2 != t1.attribute2)
and processed != 'Y'Regards
EtbinYes, you could do that. OP specifically requested something else:
wgdoig wrote:
set table1.processed = "Y"
where (table1.attribute1 = table2.attribute1)
and (table1.attribute2 = table3.attribute2)This WHERE clause won't be TRUE if any of the 4 attribute columns are NULL. It's debatable about what should be done when those columns are NULL.
But there is no argument about what needs to be done when processed is NULL.
OP didn't specifically say that the UPDATEshould or shouldn't be done on rows where processed was already 'Y'. You (quite rightly) introduced a condition that would prevent redo from being generated and triggers from firing unnecessarily; I'm just saying that we have to be careful that the same condition doesn't keep the row from being UPDATEd when it is necessary.
Maybe you are looking for
-
To color selected cells in dynamically created table in ALV.
Hi, The requirement is to display a table (whose columns are dynamic) using ALV n to color few cells of the table based on some condition. For creating the table dynamically i have used the method cl_alv_table_create=>create_dynamic_table. Now
-
I have bought an iMac in New Zealand in 2010, which is running on 220v. I will move to the US now. What adapter do I need to run my iMac safely on 110v?
-
How can I sync my bookmarks between my iPad 3, my iPhone 4S and Safari for Windows?
Hi, I have installed iOS 6 on my iPhone 4
-
Why can't I use 'control-S' in dashboard?
I've always liked the 'control-S' function, where you select a word or paragraph and Mac reads it aloud. However there seems to be a malfunction ever since I'm using Mac OS Lion. In dashboard > dictionary, whatever I select there's no voiceover. It h
-
Where I can download the plug-in for my new camera Nikon D610 (NEF) for my Adobe Creative Suits 5 (CS5).