‎2008 Dec 03 11:01 AM
Moved to correct forum by moderator. Please also use a meaningful subject in future
Hello experts,
I have a code of the following type
select from table into i_tab where <condition>
loop at i_tab assigning <field-symbol>
read i_tab with <condition>
<execute some actions>
read i_tab with <condition2>
<execute actions>
....................
endloop.
but this is taking a lot of time.
If the number of records is more then it is looping through the records, reading the table, executing action for each and every record.
So the performance is poor.
Can someone suggest alternative ways ?
Thanks in advance.
Regards,
Chithra.
Edited by: Matt on Dec 3, 2008 1:48 PM
‎2008 Dec 03 11:03 AM
HI,
Try to code like
select from table into table i_tab where <condition>
loop at i_tab assigning <field-symbol> where <condition>
and /or <condition2>
<execute some actions>
<execute actions2>
....................
endloop.
Hope this will help.
Regards,
Rajat
‎2008 Dec 03 11:03 AM
HI,
Try to code like
select from table into table i_tab where <condition>
loop at i_tab assigning <field-symbol> where <condition>
and /or <condition2>
<execute some actions>
<execute actions2>
....................
endloop.
Hope this will help.
Regards,
Rajat
‎2008 Dec 03 11:04 AM
Hi,
Have you used binary search in read stmt.
If no, do remember to sort the fields also...
Thanks & Regards,
Krishna...
‎2008 Dec 03 11:05 AM
hello,
If you want the program to look at every record all you can do is loop and within that you do the stuff.
If you dont want the program to look at every record based on some field then you can use atnew.
dont forget to sort if you want to use atnew.
Edited by: BrightSide on Dec 3, 2008 11:06 AM
‎2008 Dec 03 11:07 AM
Hi,
I haven't understand your requirement..why ur looping the i_tab table and again in that reading the same table i_tab...
Anywayz according to your posted code i can suggest the following code...
After select stmt....find out the total no.of records in that table....
Suppose 5 records then write the logic as follows :
Do 5 times.
read table i_tab with condition 1 and condition 2
do ur action.
enddo.
Use binary search to read the table but b4 that sort the table...
Hope this will help.
Regards,
Rohan.
Edited by: Rohan on Dec 3, 2008 12:08 PM
‎2008 Dec 03 11:08 AM
Hi Jayachitra,
If you want to loop through all the records that has been selected, then i dont think you can find any alternative.
I dont think you need to use READ at first place. You are looping in itab and reading the same table inside. Instead you can directly use CASE statement or IF...ELSE condition.
If this is required, then Possible performance tuning technique for this could be as follows:
1. Try to restrict as many records as possible when you are selecting the records.
2. Also when you are Reading a table, use BINARY SEARCH. Before entering the loop, use SORT the table that you want to read. This would increase the performance in terms of READ statement.
Best Regards,
Ram.
‎2008 Dec 03 11:26 AM
Hi Jaya,
Do it this way:
Data:
count type i value 1.
Describe table t_table lines w_lines.
Do w_lines times.
READ TABLE t_table INTO wa_table INDEX count.
If condition...
<execute some actions>
elseif condition...
<execute some actions>
endif.
count = count + 1.
Enddo.With luck,
Pritam.
‎2008 Dec 03 12:36 PM
Hi,
Where exactly is your problem. Reading the same table inside the loop is not a good way, but it could be that the select query also is taking lot of time. Did you check the sql trace in ST05 to see how the select is running.
As far as the loop at itab is concerned, i would do something like this.
select from table into i_tab where <condition>
loop at i_tab assigning <field-symbol>
if <condition> " Here you woould compare the fields of the <field-symbol> with some value
<execute some actions>
if <condition2> " Here you would compare the fields of the <field-symbol> with some value
<execute actions>
....................
endloop.
No need write a Do and End do and read the table inside that loop. Simply loop at itab and check for each condition and execute the actions.
regards,
Advait
‎2008 Dec 03 12:49 PM
Please use a meaningful subject in future
‎2008 Dec 03 12:52 PM
Hi Jaya,
Use BINARY SEARCH in read statement.
Best Regards,
Flavya
‎2008 Dec 03 12:56 PM
Hi jaya,
your code is:
Hello experts,
I have a code of the following type
select from table into i_tab where <condition>
loop at i_tab assigning <field-symbol>
read i_tab with <condition>
<execute some actions>
read i_tab with <condition2>
<execute actions>
....................
endloop.
LOOP AT TAB1.
READ TABLE TAB2 WITH KEY K = TAB1-K
CHECK SY-SUBRC = 0.
ENDLOOP.
Run Time (Micro Seconds) 9,682
Join two internal tables using key/binary search
Note: In this example, TAB2 is sorted by K in ascending order.
LOOP AT TAB1.
READ TABLE TAB2 WITH KEY K = TAB1-K BINARY SEARCH.
CHECK SY-SUBRC = 0.
ENDLOOP.
Run Time (Micro Seconds) 9,751
So,you can clearly see the difference between two,
Cheers,
Meena