‎2008 Feb 27 11:01 AM
Hi friends,
Assume that it_pos is an internla table and its having more than 15000 records.
Which of the following query will optimize performance of programme. <REMOVED BY MODERATOR>
SORT it_pos BY belnr.
LOOP AT it_pos INTO wa_pos .
SELECT hkont zuonr budat blart wrbtr bschl xref3
INTO CORRESPONDING FIELDS OF wa_bsis
FROM bsis
WHERE belnr = wa_pos-belnr
AND hkont = wa_pos-konto
AND zuonr = wa_pos-zuonr
AND blart = 'WE' "IN ('WE' , 'RE' , 'RO')
AND bschl = '96'
AND shkzg = 'H'
AND budat = sta_date .
APPEND wa_bsis to it_bsis.
ENDSELECT.
ENDLOOP.
SELECT hkont zuonr budat blart wrbtr bschl xref3
INTO CORRESPONDING FIELDS OF TABLE it_bsis1
FROM bsis
FOR ALL ENTRIES IN it_pos
WHERE belnr = it_pos-belnr
AND hkont = it_pos-konto
AND zuonr = it_pos-zuonr
AND blart = 'WE' "IN ('WE' , 'RE' , 'RO')
AND bschl = '96'
AND shkzg = 'H'
AND budat = sta_date .
Regards,
s.senthil kumar
Edited by: Alvaro Tejada Galindo on Feb 27, 2008 3:52 PM
‎2008 Feb 27 11:04 AM
Hi
The second way of select option is right one.
Because in your first code .
you have loop statement then you have the select statement.
Loop statement executes in the Application layer and Select statement executes in the Database Layer.
So moving from loop to select - > time consuming and also it moves from one layer to another layer in three tier architecture.
Whereas the second one has only Select statement operating upon the Database layer . and then comes out completely.
So it is more optimal and performance is good comparatively.
Thanks and regards,
Chithra
‎2008 Feb 27 11:04 AM
hi,,
SAP Provides a transaction called SE30 Which will be use for ur query performaance..there is Tips and tricks also to improve your performance tuning...
U can use it and post me a mail.. '
<REMOVED BY MODERATOR>
Regards
Karthik.T
Edited by: Alvaro Tejada Galindo on Feb 27, 2008 3:51 PM
‎2008 Feb 27 11:04 AM
Hi
The second way of select option is right one.
Because in your first code .
you have loop statement then you have the select statement.
Loop statement executes in the Application layer and Select statement executes in the Database Layer.
So moving from loop to select - > time consuming and also it moves from one layer to another layer in three tier architecture.
Whereas the second one has only Select statement operating upon the Database layer . and then comes out completely.
So it is more optimal and performance is good comparatively.
Thanks and regards,
Chithra
‎2008 Feb 27 11:05 AM
Hi,
Second select query would give you good result, because instead of putting a select query inside a loop, better avoid such sort of coding.
SUGGESTION1: TRY TO AVOID 'INTO CORRESPONDING FIELDS' STATEMENT IN THE SECOND SELECT QUERY.
SUGGESTION 2: DONT FORGET TO CHECK THE INITIALITY OF THE INTERNAL TABLE IT_POS BEFORE USING 'FOR ALL ENTRIES'.
‎2008 Feb 27 11:07 AM
your second part is better obviously
but let me remind you that you need to remove move corresponding
because that is time consuming and other then this plz use
into workarea that will b helpful for sure
<REMOVED BY MODERATOR>
vivek
Edited by: Alvaro Tejada Galindo on Feb 27, 2008 3:52 PM
‎2008 Feb 27 11:49 AM
Hi,
the first select stmt is hitting the database table for 15000 times...instead of it you can try fetching the data into an internal table outside the loop and hit the internal table inside the loop.
this may help you out.
thanks,
teja.
‎2008 Feb 27 12:06 PM
Hi
The second way is right one. And you must to change "into corresponding fields of table" by "into table" and make shure that the internal table has te same fields in the same order as the select.
‎2008 Feb 28 1:27 AM
Hi,
In addition to the suggestions given above, you can add the following things:
1) Add company code in the query if possible
2) Also add field GJAHR
3) Arrange the fields in the where clause as per sequence of the primary key combination
Once you do this, do the trace analysis and check if the proper index is being used or not.
Hope this helps.
Regards,
Shahu
‎2008 Feb 28 2:49 AM
BUKRS is the first field of the index. Either way will be extremely slow until you add this to the WHERE clause.
Rob
‎2008 Feb 28 4:17 AM
Hi,
Avoid using select statement within loop. This will increase your execution time. Instead use 'for all entries in table1'. Make sure that u check if the table 1 is not initial before using 'for all entries'.
Using select-endselect is also not advisable. Dont use 'corresponding fields of' .Instead specify the correct field names in the same order as that of internal table.
Hope this helps u.
Regards,
Ramya
‎2008 Feb 28 5:34 AM
Hi,
Thank you friends for ur reply. I have given points on basis of first in first out .
Regards,
s.senthil kumar