0% found this document useful (0 votes)
257 views2 pages

ABAP Code For Parallel Cursor - Loop Processing - Code Gallery - SCN Wiki

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
257 views2 pages

ABAP Code For Parallel Cursor - Loop Processing - Code Gallery - SCN Wiki

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

11/8/2019 ABAP Code for Parallel Cursor - Loop Processing - Code Gallery - SCN Wiki

Getting Started Store

Community WIKI SAP Community Welcome, Guest Login Register Search the Community

Code Gallery

ABAP Code for Parallel Cursor - Loop Processing


Created by Guest, last modified by Former Member on Jun 19, 2013

Author: Karthik C Sunil


Submitted: 18-Aug-2007
Related Links:

http://karsap.blogspot.com/2007/06/avoiding-nested-loops-using-parallel_19.html
http://karsap.blogspot.com/2007/06/improved-version-of-parallel-cursor.html

Abstract
This page will explain how to code very efficiently for nested un-related tables. The article describes how to improve the performance of processing huge data amounts.

Problem Description
The most common performance problem that occurs in ABAP programs is because of huge number of records in the internal tables. The problem complexifies if a program has huge nested internal
tables. How much ever efficient data select routines are, data processing routines would be contributing significantly for the bad performance. When analysed it would be revealed that the where condition
that is used in inner loops expend a significant amount of processing time. The idea is to avoid where conditions in the inner loops by maintaining the loop indexes manually.

Conventional Code for nested loops


Error rendering macro 'code': Invalid value specified for parameter 'lang'

loop at lt_vbpa into wa_vbpa.


loop at lt_kna1 into wa_kna1 where kunnr = wa_vbpa-kunnr.

****** Your Actual logic within inner loop ******

endloop.
endloop.

Code sample: Parallel Cursor method


Error rendering macro 'code': Invalid value specified for parameter 'lang'

sort: lt_vbpa by kunnr, "Sorting by key is very important


lt_kna1 by kunnr. "Same key which is used for where condition is used here
loop at lt_vbpa into wa_vbpa.
read lt_kna1 into wa_kna1 " This sets the sy-tabix
with key kunnr = wa_vbpa-kunnr
binary search.
if sy-subrc = 0. "Does not enter the inner loop
v_kna1_index = sy-tabix.
loop at lt_kna1 into wa_kna1 from v_kna1_index. "Avoiding Where clause
if wa_kna1-kunnr <> wa_vbpa-kunnr. "This checks whether to exit out of loop
exit.
endif.

****** Your Actual logic within inner loop ******

endloop. "KNA1 Loop


endif.
endloop. " VBPA Loop

Statical Analysis
Nested loop for BSEG and BKPF internal tables were analysed for Conventional Method and Parallel Cursor methods. Following gragh explains the observations.

https://wiki.scn.sap.com/wiki/display/Snippets/ABAP+Code+for+Parallel+Cursor+-+Loop+Processing 1/2
11/8/2019 ABAP Code for Parallel Cursor - Loop Processing - Code Gallery - SCN Wiki

Observation: One can observe that as the data increases, the time taken for the nested loop increases drastically, at the same time, the Parallel cursor method did not suffer any considerable time
impact.

Verdict: Use the parallel cursor method whenever there is a need to process data in a nested loop.
abap performance snippet parallel cursor

1 Comment
Former Member
1) I am not sure if the sort on table lt_vbpa is required at all.

2) SE30 Documentation talks about O (n1+n2) runtime for a parallel cursor algorithm.

The documentation extract:

Nested loops Documentation


If ITAB1 has n1 entries and ITAB2 has n2 entries, the time needed for
the nested loop with the straightforward algorithm is O(n1 * n2),
whereas the parallel cursor approach takes only O(n1 + n2) time.
The above parallel cursor algorithm assumes that ITAB2 contains only
entries also contained in ITAB1.
If this assumption does not hold, the parallel cursor algorithm
gets slightly more complicated, but its performance characteristics
remain the same.

However for the code given here it is O (n1*log n2). Surely its a far more efficient algorithm
compared to original nested loop with O (n1*n2) runtime. BUT, I am nNot sure if this is
the intended parallel cursor algorithm. which is supposedly O (n1 + n2)

Contact Us SAP Help Portal


Privacy Terms of Use Legal Disclosure Copyright Cookie Preferences Follow SCN

https://wiki.scn.sap.com/wiki/display/Snippets/ABAP+Code+for+Parallel+Cursor+-+Loop+Processing 2/2

You might also like