‎2009 Aug 13 5:33 AM
Hi,
when do we use cursor while coding .. in which situation it must be used and why ?
I have heard that its used as a optimization technique.
I have searhced for this query in SCN but didnt get a satisfactory answer ..
‎2009 Aug 14 10:30 AM
Hello,
Parallel Cursor method is used when we need to process data across two internal tables.
Consider the following exapmple
Loop at table1 into wa_Table1.
loop at table2 into wa_table2.
{
process the data.
}
endloop. "for table2.
Endloop. "for table 1.
In the above example the values of table 2 are processed from the first record every time and ther would be considerable amount of time taken to process the data.
To counter this we use parallel cursor method.
loop at it_table1 into wa_table1.
read table it_table2 with key XXXX= wa_table1-XXXX binary search
transporting no fields.
if sy-subrc = 0.
v_variable = sy-tabix. "Table indes is made a note of in the variable v_variable
loop at it_mseg into x_mseg from v_indms. "The table is read from the index read above.
if wa_table2-XXXX <> wa_table1-XXXX.
exit.
else.
{
Required processing of the two internal tables
}
endif.
endloop.
endif.
endloop.
In the above case the second loop only starts at the record for the corresponding value of field in the first table and not from the first record each time.
This brings about a lot of time saving.
Hope this helps you.
Best Regards,
Shree Tejus.
‎2009 Aug 13 6:11 AM
Hi,
please refer the below links..
https://www.sdn.sap.com/irj/scn/wiki?path=/display/abap/selectStatementsandCURSORstatement-Performance+Analysis.
Regards
amudha
‎2009 Aug 13 1:24 PM
What do you mean, OPEN CURSOR / FETCH statements for DB access or parallel cursor technique for internal table handling, or yet another cursor?
Thomas
‎2009 Aug 14 5:12 AM
Hi thomas i meant
OPEN CURSOR / FETCH statements for DB access ...
and what is this parallel cursor technique ?
‎2009 Aug 14 8:40 AM
Personally I am using OPEN CURSOR very occasionally with the WITH HOLD addition to perform package processing of huge update tasks that require periodic database commits. A normal SELECT loop without cursor hold would be interrupted by a commit and lead to a short dump.
Other than that I see no reason to prefer OPEN CURSOR / FETCH over a normal SELECT statement.
Better don't even learn about the quite old parallel cursor technique for nested internal table access, as SORTED tables provide the same performance with much less complicated code.
Thomas
‎2009 Aug 14 10:30 AM
Hello,
Parallel Cursor method is used when we need to process data across two internal tables.
Consider the following exapmple
Loop at table1 into wa_Table1.
loop at table2 into wa_table2.
{
process the data.
}
endloop. "for table2.
Endloop. "for table 1.
In the above example the values of table 2 are processed from the first record every time and ther would be considerable amount of time taken to process the data.
To counter this we use parallel cursor method.
loop at it_table1 into wa_table1.
read table it_table2 with key XXXX= wa_table1-XXXX binary search
transporting no fields.
if sy-subrc = 0.
v_variable = sy-tabix. "Table indes is made a note of in the variable v_variable
loop at it_mseg into x_mseg from v_indms. "The table is read from the index read above.
if wa_table2-XXXX <> wa_table1-XXXX.
exit.
else.
{
Required processing of the two internal tables
}
endif.
endloop.
endif.
endloop.
In the above case the second loop only starts at the record for the corresponding value of field in the first table and not from the first record each time.
This brings about a lot of time saving.
Hope this helps you.
Best Regards,
Shree Tejus.