Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

cursor concept

kesavadas_thekkillath
Active Contributor
0 Likes
632

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 ..

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
585

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.

5 REPLIES 5
Read only

Former Member
Read only

ThomasZloch
Active Contributor
0 Likes
585

What do you mean, OPEN CURSOR / FETCH statements for DB access or parallel cursor technique for internal table handling, or yet another cursor?

Thomas

Read only

0 Likes
585

Hi thomas i meant

OPEN CURSOR / FETCH statements for DB access ...

and what is this parallel cursor technique ?

Read only

0 Likes
585

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

Read only

Former Member
0 Likes
586

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.