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

Using parallel cursor

Former Member
0 Likes
2,449

Hi all,

I just want to know the functionality of the Parallel cursor in a report program.Kindly also porvide the explanation and the sample code for the same

What is the diferrence between Double cursor read and using parallel cursor.

Thanks in advance.

krishna.

8 REPLIES 8
Read only

Former Member
0 Likes
1,477

Please see this:

[The Performance of Nested Loops|/people/rob.burbank/blog/2006/02/07/performance-of-nested-loops]

Rob

Read only

Former Member
0 Likes
1,477

hi

&----


& Form parallel_cursor&--
** text*
--


*FORM parallel_cursor. DATA: bkpf_index LIKE sy-tabix, bseg_index LIKE sy-tabix. CLEAR: bkpf_reads, bseg_reads. GET TIME FIELD start_time. SORT: bkpf_tab BY bukrs belnr gjahr, bseg_tab BY bukrs belnr gjahr. bseg_index = 1. LOOP AT bkpf_tab INTO bkpf_lin. bkpf_reads = bkpf_reads + 1. LOOP AT bseg_tab INTO bseg_lin FROM bseg_index. IF bseg_lin-bukrs <> bkpf_lin-bukrs OR bseg_lin-belnr <> bkpf_lin-belnr OR bseg_lin-gjahr <> bkpf_lin-gjahr. bseg_index = sy-tabix. EXIT. ELSE. bseg_reads = bseg_reads + 1. ENDIF. ENDLOOP. ENDLOOP. GET TIME FIELD end_time. difference = end_time - start_time. WRITE: /001 'Time for parallel cursor :', difference, /005 'Number of BKPF reads :', bkpf_reads, /005 'Number of BSEG reads :', bseg_reads.ENDFORM. " parallel_cursor

Read only

Former Member
0 Likes
1,477

Hi Krishna,

Parallel Cursor is method to drastically improve performance over nested Loop. Nested Loop - directly multiplies time of execution for each loop. Example : It outer loop takes 50 ms per iteration and inner loop takes 100 ms per iteration (average) and there are 1000 records in outer loop, 500 records in inner loop - time of execution will be

50ms * 1000 * 100ms * 500 = 2500000000 ms = 2500000 s = 41666 mins !!

Parallel Cursor Example : Go to se30 --> Tips and Trick --> Internal Tables --> Simple Algorithms --> Nested Loops ....

You will be able to find simple example with execution time compared.

Double cursor read is modification of parallel cursoe. in parallel cursor you have read statement in outer loop. Hence this can read one record from inner table. If you have more than 1 record (that too variable numbers), you can use double cursor.

Double cursor will implement nested loop with modification that inner table will be sorted and after read and checking sy-subrc looping at inner table FROM SY-TABIX...Again check in inner loop condition which you have provided in Read. If condition does not come true, exit inner loop...

Double cursor example : (highlighted portion is enhancement from parallel cursor)

sort itab_in by Matnr doc_no.

loop at itab_out.

.

.

.

read table itab_in with key matnr= ... doc_no = ..

if sy-subrc = 0.

loop at itab_in.

if itab_in-mater = itab_out-matnr and itab_in-doc_no = itab_out-doc_no.

.

.

<inner loop processing>

.

.

else.

exit.

endif.

endloop.

endif.

endloop.

Regards,

Mohaiyuddin

Read only

Former Member
0 Likes
1,477

> Parallel Cursor is method to drastically improve performance over nested Loop

This is simply not true.

I would always recommend you to use for nested loops

+ optimized reads inside (binary search, sorted table or hashed tables) inside

+ if you need another loop inside then, sorted table or read binary search loop from index.

Beware, that there is no need to sorted the table which is used for the loop, it will not help!

Read more in my blog:

Measurements on internal tables: Reads and Loops:

/people/siegfried.boes/blog/2007/09/12/runtimes-of-reads-and-loops-on-internal-tables

Parallel cursor will not really help much, they are bit better but only for very large internal tables,

and you should not forget that there both tables must be sorted. If they the tables are anyway sorted,

then you get some improvement, if they must be sorted then the improvement is low.

Parallel cursor is much more difficult to program and to test, therefore I would generally recommend it.

I have results, but not published.

Siegfried

Read only

0 Likes
1,477

Hi Siegfried,

I believe i might have exaggeratted the statement.

Of course, sorted table will have good performance, but I have Improved performance of 5 programs which took 8-10 Hours with nested loops (along with select in loop)..Removing all these improved it's execution time so much that it too 1-2 minutes for execution !!

Regards,

Mohaiyuddin

Read only

Former Member
0 Likes
1,477

@Mohaiyuddin

as I said, if you use loop and inside the loop a read without binary search, then you get runtimes which

scale quadratically with the number of lines in the internal tables, i.e. for a table with 10.000 lines with

100.000.000 !!! This will kill you.

Using a read binary search or sorted search goes down to n * logn = 4 * 10.000 ... which is already

Using hashed is even better.

And parallel cursor is even a smaller factor in front of the linear factor.

=> they are all close to linear, there is not dramatic difference between the good solutions.

Therefore it is not necessary to use parallel cursor as long as the size of the internal tables is not larger

than several 10.000 lines.

see more about nonlinearity:

/people/siegfried.boes/blog/2007/02/12/performance-problems-caused-by-nonlinear-coding

Siegfried

Siegfried

Read only

0 Likes
1,477

Hi Siegfried,

Your blog is quite good..

Of course, In my scenario, record count was > 200000, which i changed to double cursor method with Read Binary..

I never compared performance with sorted table..

Thanks for info.

Regards,

Mohaiyuddin

Read only

Former Member
0 Likes
1,477

thankyou all for your replies.