PACKAGE SIZE n in SELECT query
Hi,
When using PACKAGE SIZE n option with SELECT queries, how to determine the best/optimum value of n ? Especially when we use this for querying tables like EKPO, EKKO etc.
Regards,
Anand.
> When using PACKAGE SIZE n option with SELECT queries, how to determine the best/optimum value of n ?
The 'package size' option to the select specifies how many
rows are returned in one chunk.
According to ABAP-Doku, it is best to use it with an internal table:
DATA: itab TYPE STANDARD TABLE OF SCARR WITH NON-UNIQUE
DEFAULT KEY INITIAL SIZE 10.
FIELD-SYMBOLS: <FS> TYPE scarr.
SELECT * INTO TABLE itab PACKAGE SIZE 20 FROM scarr.
LOOP AT itab ASSIGNING <FS>.
WRITE: / <FS>-carrid, <FS>-carrname.
ENDLOOP.
ENDSELECT.
But, basically, your application's requirements determine
what's the best value for n.
If you don't want a lot of DB-access, you choose a high
value for n. If you don't want a lot of data in memory, you adjust it to a lower value.
You can also use the 'up to n rows' construct in the select to limit the number of rows fetched from the db.
thomas
Similar Messages
-
How to determine package size dynamically for select - endselect statement in ABAP
Hi All,
I was using select- edselect with package size but i have hard coding the package size. Can any one tell me the the process to determine dynamic package size so that i can use in parallel processing.Hi,
If you are looking to determine or set the value of package size dynamically then use below code for reference.
DATA: itab TYPE TABLE OF spfli,
wa like LINE OF itab,
n TYPE i.
n = 10.
SELECT carrid connid
FROM spfli
INTO CORRESPONDING FIELDS OF TABLE itab
PACKAGE SIZE n.
LOOP AT itab INTO wa.
WRITE: / wa-carrid, wa-connid.
ENDLOOP.
ENDSELECT.
If you are concerned about the performance then either use SELECT with OPEN CURSOR and CLOSE CURSOR.
Let me know if it helped?
Regards,
Zuber -
Performance : how to detrmine the package size during a select
Hi,
When you do a select using package size, how to determine the value of the package size.
Thanks for your help
MarieHi marie,
1. When you do a select using package size
Its done when number of records is very high.
and we don't want to fetch all records,
IN ONE SHOT.
2. At that time, we fetch records in BUNCHES / PACKAGES.
3. Just copy paste to get a taste of it.
REPORT abc.
DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
DATA : ctr TYPE i.
selection screen.
PARAMETERS : a TYPE c.
START-OF-SELECTION.
SELECT * FROM t001
INTO TABLE t001
PACKAGE SIZE 5 .
ctr = ctr + 1.
WRITE :/ '----
Loop Pass # ' , ctr.
LOOP AT t001.
WRITE :/ t001-bukrs , t001-butxt.
ENDLOOP.
ENDSELECT.
regards,
amit m. -
Problem in my package procedure in a select query
PROCEDURE PROCESS_ROW( P_Event IN VARCHAR2,
P_Old_Record_Key IN VARCHAR2,
P_Ledger_Id IN VARCHAR2,
P_Reference IN VARCHAR2,
P_Fund IN VARCHAR2) IS
l_cash_txn_id PF_CASH_TXNS.CASH_TXN_ID%TYPE;
l_client_id PF_CASH_TXNS.CLIENT_ID%TYPE;
l_plan_id PF_CASH_TXNS.PLAN_ID%TYPE;
l_account VARCHAR2(1);
l_plan_id VARCHAR2(100);
BEGIN
l_cash_txn_id := P_Ledger_Id;
l_client_id := SUBSTR(P_Reference, -6);
l_account := SUBSTR(P_Reference, 1, 1); -- Get first letter of reference code, this is the account type.
SELECT PLAN_ID INTO l_plan_id FROM INTEGRATION.MAPPING WHERE account = l_account;
END PROCESS_ROW;The problem is at this line:
SELECT PLAN_ID INTO l_plan_id FROM INTEGRATION.MAPPING WHERE account = l_account;
The error(s) I'm getting is:
PLS-00371: at most one declaration for 'L_PLAN_ID' is permitted
PL/SQL: ORA-00904: : invalid identifier
The INTEGRATION.MAPPING table is currently empty, I'm not sure if this would have anything to do with it?Should be more or less self-explanatory:
In your first question, the code sample shows that you've declared L_PLAN_ID twice and the error message states:
"PLS-00371: at most one declaration for 'L_PLAN_ID' is permitted"
So, although datatype or length for your variables may differ, you still cannot use the same name for a variable more than once in a PL/SQL block. -
Need help in optimisation for a select query on a large table
Hi Gurus
Please help in optimising the code. It takes 1 hr for 3-4000 records. Its very slow.
My Select is reading from a table which contains 10 Million records.
I am writing the select on large table and Retrieving the values from large tables by comparing my table which has 3-4 k records.
I am pasting the code. please help
Data: wa_i_tab1 type tys_tg_1 .
DATA: i_tab TYPE STANDARD TABLE OF tys_tg_1.
Data : wa_result_pkg type tys_tg_1,
wa_result_pkg1 type tys_tg_1.
SELECT /BIC/ZSETLRUN AGREEMENT /BIC/ZREB_SDAT /BIC/ZLITEM1 from
/BIC/PZREB_SDAT *******************THIS TABLE CONTAINS 10 MILLION RECORDS
into CORRESPONDING FIELDS OF table i_tab
FOR ALL ENTRIES IN RESULT_PACKAGE***************CONTAINS 3000-4000 RECORDS
where
/bic/ZREB_SDAT = RESULT_PACKAGE-/BIC/ZREB_SDAT
AND
AGREEMENT = RESULT_PACKAGE-AGREEMENT
AND /BIC/ZLITEM1 = RESULT_PACKAGE-/BIC/ZLITEM1.
sort RESULT_PACKAGE by AGREEMENT /BIC/ZREB_SDAT /BIC/ZLITEM1.
sort i_tab by AGREEMENT /BIC/ZREB_SDAT /BIC/ZLITEM1.
loop at RESULT_PACKAGE into wa_result_pkg.
read TABLE i_tab INTO wa_i_tab1 with key
/BIC/ZREB_SDAT =
wa_result_pkg-/BIC/ZREB_SDAT
AGREEMENT = wa_result_pkg-AGREEMENT
/BIC/ZLITEM1 = wa_result_pkg-/BIC/ZLITEM1.
IF SY-SUBRC = 0.
move wa_i_tab1-/BIC/ZSETLRUN to
wa_result_pkg-/BIC/ZSETLRUN.
wa_result_pkg1-/BIC/ZSETLRUN = wa_result_pkg-/BIC/ZSETLRUN.
modify RESULT_PACKAGE from wa_result_pkg1
TRANSPORTING /BIC/ZSETLRUN.
ENDIF.
CLEAR: wa_i_tab1,wa_result_pkg1,wa_result_pkg.
endloop.Hi,
1) RESULT_PACKAGE internal table contains any duplicate records or not bassed on the where condotion like below
2) Remove the into CORRESPONDING FIELDS OF table instead of that into table use.
refer the below code is
RESULT_PACKAGE1[] = RESULT_PACKAGE[].
sort RESULT_PACKAGE1 by /BIC/ZREB_SDAT AGREEMENT /BIC/ZLITEM1.
delete adjustant duplicate form RESULT_PACKAGE1 comparing /BIC/ZREB_SDAT AGREEMENT /BIC/ZLITEM1.
SELECT /BIC/ZSETLRUN AGREEMENT /BIC/ZREB_SDAT /BIC/ZLITEM1
from /BIC/PZREB_SDAT
into table i_tab
FOR ALL ENTRIES IN RESULT_PACKAGE1
where
/bic/ZREB_SDAT = RESULT_PACKAGE1-/BIC/ZREB_SDAT
AND
AGREEMENT = RESULT_PACKAGE1-AGREEMENT
AND /BIC/ZLITEM1 = RESULT_PACKAGE1-/BIC/ZLITEM1.
and one more thing your getting 10 million records so use package size in you select query.
Refer the following link also For All Entry for 1 Million Records
Regards,
Dhina..
Edited by: Dhina DMD on Sep 15, 2011 7:17 AM -
hi experts,
please help in usage of package size in select query with where clouses
without for all enteries
regards
prashantHi Prashant,
Package size option in select query is useful in multiple cases:
- When the number of records accessed by the select query for the given where clause are very large and it may slow down the performance of the program. In this case package size option is used such that data is fetched in multiple hits.
- If the program is checking for a particular record from the database table having very large number of records without knowing the actual key. In this case package size can be used such that we can check for the existence of the required record after each fetching and can be exited from loop immediately after finding the record.
Thanks,
Sankar -
Select query with package size
Hi ,
i am trying to use select qurey with package size , to limt the data fetching .
Can any one gives sqample code or idea select query using 'package size'.
Advance Thanks,
Regards
veeraHi,
SELECT vbeln erdat
FROM vbak
INTO TABLE li_vbak PACKAGE SIZE 50.
SELECT posnr matnr meins
FROM vbap
INTO TABLE li_vbap
FOR ALL ENTRIES IN li_vbak
WHERE vbeln = li_vbak-vbeln.
Hi i want to select only from vbeln ,ie single selct query only using pakage size.200,blocks in data base ..How ?
Regards
veera -
Hi all,
Can any body help for how to use package size in select statemtent.
I want to seletc record in lot of 300 form 10k records.
And i am using 4.6c version and wnat to know this statement (package size) is there in 4.6c.
I know it is in 6.0.Hi
Package size in SELECT statements
Package size can be used to retreive a spcific number of records at a time. This can be used if you
for example only want tofinish processing a limited amount of data at a time due to lack of memory.
The exampel below read 50 records at a time from VBAK into an internal table, and selects the
corresponding entries from vbap into an internal table. Then the two internal tables can be
processed, and the next 50 records from VBAk can be read. remeber to reinitialize tha tables before
the next read.
Note the usage of SELECT - ENDSELECT !
REPORT z_test .
TYPES:
BEGIN OF t_vbak,
vbeln LIKE vbak-vbeln,
erdat LIKE vbak-erdat,
END OF t_vbak,
BEGIN OF t_vbap,
posnr LIKE vbap-posnr,
matnr LIKE vbap-matnr,
meins LIKE vbap-meins,
END OF t_vbap,
BEGIN OF t_report,
vbeln LIKE vbak-vbeln,
erdat LIKE vbak-erdat,
posnr LIKE vbap-posnr,
matnr LIKE vbap-matnr,
meins LIKE vbap-meins,
END OF t_report.
DATA:
li_vbak TYPE t_vbak OCCURS 0,
l_vbak TYPE t_vbak,
li_vbap TYPE t_vbap OCCURS 0,
l_vbap TYPE t_vbap,
li_report TYPE t_report OCCURS 0,
l_report TYPE t_report.
START-OF-SELECTION.
SELECT vbeln erdat
FROM vbak
INTO TABLE li_vbak PACKAGE SIZE 50.
SELECT posnr matnr meins
FROM vbap
INTO TABLE li_vbap
FOR ALL ENTRIES IN li_vbak
WHERE vbeln = li_vbak-vbeln.
IF sy-subrc = 0.
Now you have the two internal tables li_vbak and liÆ_vbap filled with data.
Do something with the data - remember to reinitialize internal tables
ENDIF.
ENDSELECT.
All of the product names here are trademarks of their respective companies. The site
www.allsaplinks.com no way affiliated with SAP AG. We have made every effort for the content
integrity. Information used on this site is at your own risk.
+
REWARD IF USEFULL+ -
Error in select query with package size
Hi Experts,
I have an issue.
SELECT * FROM (w_tab-tablename) I
NTO CORRESPONDING FIELDS OF TABLE <lt_data> PACKAGE SIZE 10000.
Am splitting the table for every 10000 records,for first time the select query is successful.
But when it comes for the second 10000 records,its throwing the following dump.
"DBIF_RSQL_INVALID_CURSOR"
Help AppreciatedHi,
There are a few instances where you get this error.
1) If you are debugging inside select ... endselect.
2) You have written any of the below statements inside select ... endselect.
Please look at the dump .. you'll find the below ..
MESSAGE (apart from MESSAGE S...)
COMMIT WORK
ROLLBACK WORK
BREAK-POINT
WAIT
CALL FUNCTION ... DESTINATION (synchronous RFC)
CALL FUNCTION ... STARTING NEW TASK
RECEIVE RESULTS
CALL DIALOG
CALL SELECTION-SCREEN
CALL TRANSACTION
CALL SCREEN, or any other statement that results in the display of a
new screen
Regards,
Srini. -
Will it improve performance if PACKAGE SIZE added to a select query?
Hi Gurus
While doing the performance optimization I could see that in the code it is splitting the BKPF entries selected to a package of 500 and selecting from BSEG cluster table. In effect the remaining tables are also getting hit based on the no. of entries(packets) in the selected BKPF internal table.
Cant we use the package size 500 in the select statement instead of this spliting and hiting the tables in a do loop.
eg:-
SELECT x v z
FROM bseg
APPENDING TABLE lt_bseg
PACKAGE SIZE 500
FOR ALL ENTRIES IN lt_coep
WHERE bukrs = lt_coep-bukrs
AND belnr = lt_coep-belnr_fi
AND gjahr = lt_coep-gjahr.
When I read the keyword documentation I saw a note in that as " If the addition PACKAGE SIZE is specified together with FOR ALL ENTRIES, it is not passed to the database system, but is applied to the result set on the application server, after all selected rows have been read" I did not understand the meaning of this.
So I am confused whether I can go ahead with this approach or will go along with the already used BKPF split logic and selct from BSEG and other tables in DO loop.
Can you please help me << removed >>.
Thanks & Regards,
Shinimol.
Edited by: Rob Burbank on Sep 23, 2010 9:09 AMHi,
regarding your second doubt:
> Second doubt is on the note I saw in key word documentation. " If the addition PACKAGE SIZE is specified together with FOR ALL ENTRIES, it is not passed to the database system, but is applied to the result set on the application server, after all selected rows have been read. " I couldn't understnd this. When I debugged the select with F5 it was selecting 500 each till it reaches th end.
> So what does it mean, we can use this option or we should not use?
the FAE does your select in pieces and collects the result in the database interface in an inermediate buffer and
eliminates the duplicates there. AFTER this it gives you the number of rows back to your ABAP program that are specified with package size. It simply means that the package size addition has no effect on the memory consumptionfor the intermediate
buffer in the database interface.
Kind regards,
Hermann -
Select command using package size
Hi all,
I have to fetch the same record comparing the records from two data base table for which i m using
select * from dbtab1 into table itab1 package size n
select * from dbtab2 into itab2
where field = itab1-field.
endselect.
the loop of select is executed once for second time its givin dump.
please help.
regards,
GayatriHi Gayatri,
You can try following code:
DATA: l_itab1 LIKE itab1 OCCURS 0 WITH HEADER LINE.
Select first data for first select statement. Then select data for second select statement outside the ***** first select statement.
SELECT *
FROM dbtab1
INTO TABLE itab1
PACKAGE SIZE n
ENDSELECT.
IF NOT itab1[] IS INITIAL.
SORT itab1 by field.
l_itab1[] = itab1[].
SELECT *
FOR ALL ENTRIES IN l_itab1
FROM dbtab2
INTO itab2
WHERE field = l_itab1-field.
ENDIF.
Hope this help you.
Regards,
Anil
Edited by: Anil Salekar on Feb 23, 2009 11:45 AM -
HI All experts,<br><br>
i have a program in which i have a select query <pre>
SELECT b~vertrag
a~anlage
a~operand
a~saison
a~ab
a~ablfdnr
a~bis
a~wert1
FROM ettifn AS a INNER JOIN ever AS b
ON aanlage = banlage
INTO TABLE li_captran PACKAGE SIZE p_pack
WHERE a~anlage IN s_anlage
AND a~ab <= l_date
AND a~bis >= l_date
AND a~operand IN ('ID-CAPLOAD','ID-OBLT')
AND b~einzdat <= l_date
AND b~auszdat >= l_date.</pre><br><br>
this query is taking a lot of time in running and we are facing lot of performance related issues
<br><br>
kindly guide me how i can break this into som simpler query
<br><br>
ettifn has 10 million records
ever has around 5 million records .
<br><br>
also please tell me how much data i can store into an internal table
can i store 5 million records in an internal table ??????
is it good in terms of performance of a program if not please tell me what is the better way of doing dat .
<br><br>
also tell me how secondry indexes help in improving performance of select query
is it good to maintain number of secondry indexes in a standard table or it decreases performance of a standard table .
<br><br>
<pre>
TYPES: BEGIN OF ty_eanlh,
anlage LIKE eanlh-anlage,
bis LIKE eanlh-bis,
tariftyp LIKE eanlh-tariftyp,
END OF ty_eanlh.
DATA: l_date TYPE datum.
DATA: li_eanlh TYPE HASHED TABLE OF ty_eanlh WITH UNIQUE KEY anlage
bis
WITH HEADER LINE.
DATA: li_captran TYPE HASHED TABLE OF ty_captran WITH UNIQUE KEY vertrag
anlage
operand
saison
ab
ablfdnr
WITH HEADER LINE.
DATA: l_tariftyp LIKE eanlh-tariftyp.
l_date = p_date + 6.
l_date = p_date + 5. "As per Terry's Request 1/23/2009
CHECK NOT p_cap IS INITIAL.
Get Operand Values
SELECT b~vertrag
a~anlage
a~operand
a~saison
a~ab
a~ablfdnr
a~bis
a~wert1
FROM ettifn AS a INNER JOIN ever AS b
ON aanlage = banlage
INTO TABLE li_captran PACKAGE SIZE p_pack
WHERE a~anlage IN s_anlage
AND a~ab <= l_date
AND a~bis >= l_date
AND a~operand IN ('ID-CAPLOAD','ID-OBLT')
AND b~einzdat <= l_date
AND b~auszdat >= l_date.
IF sy-subrc EQ 0 AND NOT li_captran[] IS INITIAL.
Get Rate Category
SELECT anlage
bis
tariftyp
FROM eanlh INTO CORRESPONDING FIELDS OF TABLE li_eanlh
FOR ALL ENTRIES IN li_captran
WHERE anlage = li_captran-anlage
AND ab <= l_date
AND bis >= l_date.
Get POD ID
SELECT a~anlage
a~int_ui
a~dateto
a~timeto
b~ext_ui
INTO TABLE i_pod
FROM euiinstln AS a INNER JOIN euitrans AS b
ON aint_ui = bint_ui
FOR ALL ENTRIES IN li_captran
WHERE a~anlage = li_captran-anlage.
IF sy-subrc EQ 0 AND NOT i_pod[] IS INITIAL.
SORT i_pod BY anlage.
SELECT vertrag
int_ui
serviceid
FROM eservice
INTO TABLE i_servicect
FOR ALL ENTRIES IN i_pod
WHERE int_ui = i_pod-int_ui
AND service_start <= l_date
AND service_end >= l_date
AND service = 'ESUP'.
ENDIF.
LOOP AT li_captran.
i_ct-anlage = li_captran-anlage.
READ TABLE li_eanlh WITH KEY anlage = li_captran-anlage.
IF sy-subrc EQ 0.
i_ct-tariftyp = li_eanlh-tariftyp.
READ TABLE i_rate WITH KEY tariftyp = i_ct-tariftyp.
IF sy-subrc NE 0.
CONTINUE.
ENDIF.
ELSE.
i_ct-tariftyp = '0000'.
ENDIF.
READ TABLE i_pod WITH KEY anlage = li_captran-anlage.
IF sy-subrc EQ 0.
READ TABLE i_servicect WITH KEY int_ui = i_pod-int_ui.
IF sy-subrc EQ 0.
i_ct-serviceid = i_servicect-serviceid.
ENDIF.
ENDIF.
IF li_captran-operand = 'ID-CAPLOAD'.
i_ct-cap = li_captran-wert1.
ELSEIF li_captran-operand = 'ID-OBLT'.
i_ct-tran = li_captran-wert1.
ENDIF.
COLLECT i_ct.
CLEAR: li_captran, i_ct.
ENDLOOP.
ENDIF.
ENDSELECT.</pre><br><br>
this code is taking a lot of time to execute and decreasing the system performance .<br><br>
please guide me how can i increase the performance of this code .<br><br>
Thanks in advance<br><br><br><br>
Edited by: Matt on Oct 11, 2009 9:45 PMHi matt ,
no i am not thru bcoz of formatting i just trying to remove it and i just marked it answered so that it will not come in my unanswered because unanswered questions are limited.
also could you please help me in this question .
now how can i change this question to unanswerd .
plz guide me
Thanks in advance -
Performance issue after Upgrade from 4.7 to ECC 6.0 with a select query
Hi All,
There is a Performance issue after Upgrade from 4.7 to ECC 6.0 with a select query in a report painter.
This query is working fine when executed in 4.7 system where as it is running for more time in ECC6.0.
Select query is on the table COSP.
SELECT (FIELD_LIST)
INTO CORRESPONDING FIELDS OF TABLE I_COSP PACKAGE SIZE 1000
FROM COSP CLIENT SPECIFIED
WHERE GJAHR IN SELR_GJAHR
AND KSTAR IN SELR_KSTAR
AND LEDNR EQ '00'
AND OBJNR IN SELR_OBJNR
AND PERBL IN SELR_PERBL
AND VERSN IN SELR_VERSN
AND WRTTP IN SELR_WRTTP
AND MANDT IN MANDTTAB
GROUP BY (GROUP_LIST).
LOOP AT I_COSP .
COSP = I_COSP .
PERFORM PCOSP USING I_COSP-_COUNTER.
CLEAR: $RWTAB, COSP .
CLEAR CCR1S .
ENDLOOP.
ENDSELECT.
I have checked with the table indexes, they were same as in 4.7 system.
What can be the reson for the difference in execution time. How can this be reduced without adjusting the select query.
Thanks in advance for the responses.
Regards,
Dedeepya.Hi,
ohhhhh....... lots of problems in select query......this is not the way you should write it.
Some generic comments:
1. never use SELECT
endselect.
SELECT
into table
for all entries in table
where.
use perform statment after this selection.
2. Do not use into corresponding fields. use exact structure type.
3. use proper sequence of fields in the where condition so that it helps table go according to indexes.
e.g in your case
sequence should be
LEDNR
OBJNR
GJAHR
WRTTP
VERSN
KSTAR
HRKFT
VRGNG
VBUND
PARGB
BEKNZ
TWAER
PERBL
sequence should be same as defined in table.
Always keep select query as simple as possible and perform all other calculations etc. afterwords.
I hope it helps.
Regards,
Pranaya -
SELECT query takes too much time! Y?
Plz find my SELECT query below:
select w~mandt
wvbeln wposnr wmeins wmatnr wwerks wnetwr
wkwmeng wvrkme wmatwa wcharg w~pstyv
wposar wprodh wgrkor wantlf wkztlf wlprio
wvstel wroute wumvkz wumvkn wabgru wuntto
wawahr werdat werzet wfixmg wprctr wvpmat
wvpwrk wmvgr1 wmvgr2 wmvgr3 wmvgr4 wmvgr5
wbedae wcuobj w~mtvfp
xetenr xwmeng xbmeng xettyp xwepos xabart
x~edatu
xtddat xmbdat xlddat xwadat xabruf xetart
x~ezeit
into table t_vbap
from vbap as w
inner join vbep as x on xvbeln = wvbeln and
xposnr = wposnr and
xmandt = wmandt
where
( ( werdat > pre_dat ) and ( werdat <= w_date ) ) and
( ( ( erdat > pre_dat and erdat < p_syndt ) or
( erdat = p_syndt and erzet <= p_syntm ) ) ) and
w~matnr in s_matnr and
w~pstyv in s_itmcat and
w~lfrel in s_lfrel and
w~abgru = ' ' and
w~kwmeng > 0 and
w~mtvfp in w_mtvfp and
x~ettyp in w_ettyp and
x~bdart in s_req_tp and
x~plart in s_pln_tp and
x~etart in s_etart and
x~abart in s_abart and
( ( xlifsp in s_lifsp ) or ( xlifsp = ' ' ) ).
The problem: It takes too much time while executing this statement.
Could anybody change this statement and help me out to reduce the DB Access time?
ThxWays of Performance Tuning
1. Selection Criteria
2. Select Statements
Select Queries
SQL Interface
Aggregate Functions
For all Entries
Select Over more than one internal table
Selection Criteria
1. Restrict the data to the selection criteria itself, rather than filtering it out using the ABAP code using CHECK statement.
2. Select with selection list.
SELECT * FROM SBOOK INTO SBOOK_WA.
CHECK: SBOOK_WA-CARRID = 'LH' AND
SBOOK_WA-CONNID = '0400'.
ENDSELECT.
The above code can be much more optimized by the code written below which avoids CHECK, selects with selection list
SELECT CARRID CONNID FLDATE BOOKID FROM SBOOK INTO TABLE T_SBOOK
WHERE SBOOK_WA-CARRID = 'LH' AND
SBOOK_WA-CONNID = '0400'.
Select Statements Select Queries
1. Avoid nested selects
SELECT * FROM EKKO INTO EKKO_WA.
SELECT * FROM EKAN INTO EKAN_WA
WHERE EBELN = EKKO_WA-EBELN.
ENDSELECT.
ENDSELECT.
The above code can be much more optimized by the code written below.
SELECT PF1 PF2 FF3 FF4 INTO TABLE ITAB
FROM EKKO AS P INNER JOIN EKAN AS F
ON PEBELN = FEBELN.
Note: A simple SELECT loop is a single database access whose result is passed to the ABAP program line by line. Nested SELECT loops mean that the number of accesses in the inner loop is multiplied by the number of accesses in the outer loop. One should therefore use nested SELECT loops only if the selection in the outer loop contains very few lines or the outer loop is a SELECT SINGLE statement.
2. Select all the records in a single shot using into table clause of select statement rather than to use Append statements.
SELECT * FROM SBOOK INTO SBOOK_WA.
CHECK: SBOOK_WA-CARRID = 'LH' AND
SBOOK_WA-CONNID = '0400'.
ENDSELECT.
The above code can be much more optimized by the code written below which avoids CHECK, selects with selection list and puts the data in one shot using into table
SELECT CARRID CONNID FLDATE BOOKID FROM SBOOK INTO TABLE T_SBOOK
WHERE SBOOK_WA-CARRID = 'LH' AND
SBOOK_WA-CONNID = '0400'.
3. When a base table has multiple indices, the where clause should be in the order of the index, either a primary or a secondary index.
To choose an index, the optimizer checks the field names specified in the where clause and then uses an index that has the same order of the fields. In certain scenarios, it is advisable to check whether a new index can speed up the performance of a program. This will come handy in programs that access data from the finance tables.
4. For testing existence, use Select.. Up to 1 rows statement instead of a Select-Endselect-loop with an Exit.
SELECT * FROM SBOOK INTO SBOOK_WA
UP TO 1 ROWS
WHERE CARRID = 'LH'.
ENDSELECT.
The above code is more optimized as compared to the code mentioned below for testing existence of a record.
SELECT * FROM SBOOK INTO SBOOK_WA
WHERE CARRID = 'LH'.
EXIT.
ENDSELECT.
5. Use Select Single if all primary key fields are supplied in the Where condition .
If all primary key fields are supplied in the Where conditions you can even use Select Single.
Select Single requires one communication with the database system, whereas Select-Endselect needs two.
Select Statements SQL Interface
1. Use column updates instead of single-row updates
to update your database tables.
SELECT * FROM SFLIGHT INTO SFLIGHT_WA.
SFLIGHT_WA-SEATSOCC =
SFLIGHT_WA-SEATSOCC - 1.
UPDATE SFLIGHT FROM SFLIGHT_WA.
ENDSELECT.
The above mentioned code can be more optimized by using the following code
UPDATE SFLIGHT
SET SEATSOCC = SEATSOCC - 1.
2. For all frequently used Select statements, try to use an index.
SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA
WHERE CARRID = 'LH'
AND CONNID = '0400'.
ENDSELECT.
The above mentioned code can be more optimized by using the following code
SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA
WHERE MANDT IN ( SELECT MANDT FROM T000 )
AND CARRID = 'LH'
AND CONNID = '0400'.
ENDSELECT.
3. Using buffered tables improves the performance considerably.
Bypassing the buffer increases the network considerably
SELECT SINGLE * FROM T100 INTO T100_WA
BYPASSING BUFFER
WHERE SPRSL = 'D'
AND ARBGB = '00'
AND MSGNR = '999'.
The above mentioned code can be more optimized by using the following code
SELECT SINGLE * FROM T100 INTO T100_WA
WHERE SPRSL = 'D'
AND ARBGB = '00'
AND MSGNR = '999'.
Select Statements Aggregate Functions
If you want to find the maximum, minimum, sum and average value or the count of a database column, use a select list with aggregate functions instead of computing the aggregates yourself.
Some of the Aggregate functions allowed in SAP are MAX, MIN, AVG, SUM, COUNT, COUNT( * )
Consider the following extract.
Maxno = 0.
Select * from zflight where airln = LF and cntry = IN.
Check zflight-fligh > maxno.
Maxno = zflight-fligh.
Endselect.
The above mentioned code can be much more optimized by using the following code.
Select max( fligh ) from zflight into maxno where airln = LF and cntry = IN.
Select Statements For All Entries
The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of entries in the driver table is larger than rsdb/max_blocking_factor, several similar SQL statements are executed to limit the length of the WHERE clause.
The plus
Large amount of data
Mixing processing and reading of data
Fast internal reprocessing of data
Fast
The Minus
Difficult to program/understand
Memory could be critical (use FREE or PACKAGE size)
Points to be must considered FOR ALL ENTRIES
Check that data is present in the driver table
Sorting the driver table
Removing duplicates from the driver table
Consider the following piece of extract
Loop at int_cntry.
Select single * from zfligh into int_fligh
where cntry = int_cntry-cntry.
Append int_fligh.
Endloop.
The above mentioned can be more optimized by using the following code.
Sort int_cntry by cntry.
Delete adjacent duplicates from int_cntry.
If NOT int_cntry[] is INITIAL.
Select * from zfligh appending table int_fligh
For all entries in int_cntry
Where cntry = int_cntry-cntry.
Endif.
Select Statements Select Over more than one Internal table
1. Its better to use a views instead of nested Select statements.
SELECT * FROM DD01L INTO DD01L_WA
WHERE DOMNAME LIKE 'CHAR%'
AND AS4LOCAL = 'A'.
SELECT SINGLE * FROM DD01T INTO DD01T_WA
WHERE DOMNAME = DD01L_WA-DOMNAME
AND AS4LOCAL = 'A'
AND AS4VERS = DD01L_WA-AS4VERS
AND DDLANGUAGE = SY-LANGU.
ENDSELECT.
The above code can be more optimized by extracting all the data from view DD01V_WA
SELECT * FROM DD01V INTO DD01V_WA
WHERE DOMNAME LIKE 'CHAR%'
AND DDLANGUAGE = SY-LANGU.
ENDSELECT
2. To read data from several logically connected tables use a join instead of nested Select statements. Joins are preferred only if all the primary key are available in WHERE clause for the tables that are joined. If the primary keys are not provided in join the Joining of tables itself takes time.
SELECT * FROM EKKO INTO EKKO_WA.
SELECT * FROM EKAN INTO EKAN_WA
WHERE EBELN = EKKO_WA-EBELN.
ENDSELECT.
ENDSELECT.
The above code can be much more optimized by the code written below.
SELECT PF1 PF2 FF3 FF4 INTO TABLE ITAB
FROM EKKO AS P INNER JOIN EKAN AS F
ON PEBELN = FEBELN.
3. Instead of using nested Select loops it is often better to use subqueries.
SELECT * FROM SPFLI
INTO TABLE T_SPFLI
WHERE CITYFROM = 'FRANKFURT'
AND CITYTO = 'NEW YORK'.
SELECT * FROM SFLIGHT AS F
INTO SFLIGHT_WA
FOR ALL ENTRIES IN T_SPFLI
WHERE SEATSOCC < F~SEATSMAX
AND CARRID = T_SPFLI-CARRID
AND CONNID = T_SPFLI-CONNID
AND FLDATE BETWEEN '19990101' AND '19990331'.
ENDSELECT.
The above mentioned code can be even more optimized by using subqueries instead of for all entries.
SELECT * FROM SFLIGHT AS F INTO SFLIGHT_WA
WHERE SEATSOCC < F~SEATSMAX
AND EXISTS ( SELECT * FROM SPFLI
WHERE CARRID = F~CARRID
AND CONNID = F~CONNID
AND CITYFROM = 'FRANKFURT'
AND CITYTO = 'NEW YORK' )
AND FLDATE BETWEEN '19990101' AND '19990331'.
ENDSELECT.
1. Table operations should be done using explicit work areas rather than via header lines.
READ TABLE ITAB INTO WA WITH KEY K = 'X BINARY SEARCH.
IS MUCH FASTER THAN USING
READ TABLE ITAB INTO WA WITH KEY K = 'X'.
If TAB has n entries, linear search runs in O( n ) time, whereas binary search takes only O( log2( n ) ).
2. Always try to use binary search instead of linear search. But dont forget to sort your internal table before that.
READ TABLE ITAB INTO WA WITH KEY K = 'X'. IS FASTER THAN USING
READ TABLE ITAB INTO WA WITH KEY (NAME) = 'X'.
3. A dynamic key access is slower than a static one, since the key specification must be evaluated at runtime.
4. A binary search using secondary index takes considerably less time.
5. LOOP ... WHERE is faster than LOOP/CHECK because LOOP ... WHERE evaluates the specified condition internally.
LOOP AT ITAB INTO WA WHERE K = 'X'.
ENDLOOP.
The above code is much faster than using
LOOP AT ITAB INTO WA.
CHECK WA-K = 'X'.
ENDLOOP.
6. Modifying selected components using MODIFY itab TRANSPORTING f1 f2.. accelerates the task of updating a line of an internal table.
WA-DATE = SY-DATUM.
MODIFY ITAB FROM WA INDEX 1 TRANSPORTING DATE.
The above code is more optimized as compared to
WA-DATE = SY-DATUM.
MODIFY ITAB FROM WA INDEX 1.
7. Accessing the table entries directly in a "LOOP ... ASSIGNING ..." accelerates the task of updating a set of lines of an internal table considerably
Modifying selected components only makes the program faster as compared to Modifying all lines completely.
e.g,
LOOP AT ITAB ASSIGNING <WA>.
I = SY-TABIX MOD 2.
IF I = 0.
<WA>-FLAG = 'X'.
ENDIF.
ENDLOOP.
The above code works faster as compared to
LOOP AT ITAB INTO WA.
I = SY-TABIX MOD 2.
IF I = 0.
WA-FLAG = 'X'.
MODIFY ITAB FROM WA.
ENDIF.
ENDLOOP.
8. If collect semantics is required, it is always better to use to COLLECT rather than READ BINARY and then ADD.
LOOP AT ITAB1 INTO WA1.
READ TABLE ITAB2 INTO WA2 WITH KEY K = WA1-K BINARY SEARCH.
IF SY-SUBRC = 0.
ADD: WA1-VAL1 TO WA2-VAL1,
WA1-VAL2 TO WA2-VAL2.
MODIFY ITAB2 FROM WA2 INDEX SY-TABIX TRANSPORTING VAL1 VAL2.
ELSE.
INSERT WA1 INTO ITAB2 INDEX SY-TABIX.
ENDIF.
ENDLOOP.
The above code uses BINARY SEARCH for collect semantics. READ BINARY runs in O( log2(n) ) time. The above piece of code can be more optimized by
LOOP AT ITAB1 INTO WA.
COLLECT WA INTO ITAB2.
ENDLOOP.
SORT ITAB2 BY K.
COLLECT, however, uses a hash algorithm and is therefore independent
of the number of entries (i.e. O(1)) .
9. "APPEND LINES OF itab1 TO itab2" accelerates the task of appending a table to another table considerably as compared to LOOP-APPEND-ENDLOOP.
APPEND LINES OF ITAB1 TO ITAB2.
This is more optimized as compared to
LOOP AT ITAB1 INTO WA.
APPEND WA TO ITAB2.
ENDLOOP.
10. DELETE ADJACENT DUPLICATES accelerates the task of deleting duplicate entries considerably as compared to READ-LOOP-DELETE-ENDLOOP.
DELETE ADJACENT DUPLICATES FROM ITAB COMPARING K.
This is much more optimized as compared to
READ TABLE ITAB INDEX 1 INTO PREV_LINE.
LOOP AT ITAB FROM 2 INTO WA.
IF WA = PREV_LINE.
DELETE ITAB.
ELSE.
PREV_LINE = WA.
ENDIF.
ENDLOOP.
11. "DELETE itab FROM ... TO ..." accelerates the task of deleting a sequence of lines considerably as compared to DO -DELETE-ENDDO.
DELETE ITAB FROM 450 TO 550.
This is much more optimized as compared to
DO 101 TIMES.
DELETE ITAB INDEX 450.
ENDDO.
12. Copying internal tables by using ITAB2[ ] = ITAB1[ ] as compared to LOOP-APPEND-ENDLOOP.
ITAB2[] = ITAB1[].
This is much more optimized as compared to
REFRESH ITAB2.
LOOP AT ITAB1 INTO WA.
APPEND WA TO ITAB2.
ENDLOOP.
13. Specify the sort key as restrictively as possible to run the program faster.
SORT ITAB BY K. makes the program runs faster as compared to SORT ITAB.
Internal Tables contd
Hashed and Sorted tables
1. For single read access hashed tables are more optimized as compared to sorted tables.
2. For partial sequential access sorted tables are more optimized as compared to hashed tables
Hashed And Sorted Tables
Point # 1
Consider the following example where HTAB is a hashed table and STAB is a sorted table
DO 250 TIMES.
N = 4 * SY-INDEX.
READ TABLE HTAB INTO WA WITH TABLE KEY K = N.
IF SY-SUBRC = 0.
ENDIF.
ENDDO.
This runs faster for single read access as compared to the following same code for sorted table
DO 250 TIMES.
N = 4 * SY-INDEX.
READ TABLE STAB INTO WA WITH TABLE KEY K = N.
IF SY-SUBRC = 0.
ENDIF.
ENDDO.
Point # 2
Similarly for Partial Sequential access the STAB runs faster as compared to HTAB
LOOP AT STAB INTO WA WHERE K = SUBKEY.
ENDLOOP.
This runs faster as compared to
LOOP AT HTAB INTO WA WHERE K = SUBKEY.
ENDLOOP. -
Time out problem for select query
I am fetching data from BKPF for my report.
I have written following query.But this query always time out.
SELECT
BUKRS
BELNR
GJAHR
BLART
BLDAT
BUDAT
MONAT
XBLNR
BKTXT
WAERS
KURSF
HWAER
FROM BKPF
INTO TABLE I_BKPF
WHERE BUKRS IN S_BUKRS
AND BELNR IN S_BELNR
AND GJAHR IN S_GJAHR
AND BLART IN S_BLART
AND BLDAT IN S_BLDAT
AND BUDAT IN S_BUDAT
AND MONAT IN S_MONAT
AND CPUDT IN S_CPUDT
AND BSTAT = SPACE.
So please suggest me solution.Hi..
1) Try to make Some of the Fields such as BUKRS , GJAHR as PARAMETERS so that ROWS are restrited mostly.
2) Make fields like BLDAT and BUDAT as OBLIGATORY if possible.
3) And in the SELECT query add the PACKAGE SIZE addition.
<b>Reward if Helpful.</b>
Maybe you are looking for
-
OS 8.6 to 9.2.2
I am considering installing os9 over existing 8.6 to accomodate msn messenger 2.5.1 which I understand is the only email software that runs on classic macs. What problems should I anticipate? 9500 PowerPC G3 Mac OS 8.6 or Earlier 394Mhz
-
MDG-S BP Grouping,BP Role,BP Categeory and ERP Vendoe Account Group
Hi Can anybody explains me releationship between MDG-S BP Grouping,BP Role,BP Categeory and ERP Vendoe Account Group? It seems there is no requried field except Change Request Description.If we input value for CR Description only, we can still able t
-
Airport express is blocking the use of Morpheus
I am having trouble configuring the airport express in order to allow me to use Morpheus properly. I subsribed to morpheus and now I am unable to download anything as it is being firewalled by the ariport. How do I disable this?
-
Business system for legacy system
hi guys, Can we create business system for legacy system ?If yes what is the use? satya reddy
-
Remapping function keys the way users need them to
Expose was a feature that I used seamlessly when going between apps on a MacBook. Ever since I got a MacBook Pro it's been frustrating using Expose and Spaces ever since. 1. I never did use the hot corners. Way too many inadvertent calls, especially