Tuesday, June 19, 2007

Avoiding Nested Loops Using Parallel Cursors

Background: Performance of program, function modules, BAdi or any piece of code would drastically go down when:


  1. Nested loops are used

  2. Corresponding internal tables are very huge

  3. When child table is larger than the parent table
Statistics:
Sample program run with different number of BKPF and BSEG tables entries is shown below:

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

Verdict: Use parallel cursor method whenever there is a need to have nested loop.

Method:
Assume you fill up bkpf_tab and bseg_tab.
Code for normal nested loop: ( I consider this as UGLY code from now onwards)



loop at bkpf_tab into bkpf_lin.
bkpf_reads = bkpf_reads + 1.
loop at bseg_tab into bseg_lin where
bukrs = bkpf_lin-bukrs and
belnr = bkpf_lin-belnr and
gjahr = bkpf_lin-gjahr.
bseg_reads = bseg_reads + 1.
endloop.
endloop.

Code for Parallel Cursor:


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.

Go through these code and post your comments

Analysis:
In the so called UGLY code, for every record in parent table (BKPF), the whole child table (BSEG) is searched and hence the delay. In Parallel cursor code both the tables are sorted and child table is not accessed completely, instead the index is stored in every iteration of the child table, once all the child records for current parent record is over, the index of the current child record is used for accessing first child record of next parent entry without searching the entire table. This is doen using 'FROM' clause of the loop. The where condition for the child loop should be avoided at any cost. Store the index and use the same for the next parent record. As the tables are sorted, this method should work excellently.

Going forward:
I would add a checkilist item for my code review to check for Parallel cursor for any place where a Nested loop is involved.

Labels: , , , ,

27 Comments:

Anonymous Anonymous said...

viagra dosages viagra cheap price iframe no prescription viagra sample of viagra viagra prices viagra rrp australia viagra suppliers cialis levia and viagra non prescription viagra generic brands of viagra online viagra buy price iframe womens viagra viagra online uk can viagra causes legs to ache

November 12, 2009 6:15 AM  

~ * ~

Anonymous Anonymous said...

Hello,

I keep coming to this website[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url]Lots of good information here karsap.blogspot.com. Frankly speaking we really do not pay attention towards our health. Let me show you one truth. Research indicates that about 90% of all United States grownups are either fat or weighty[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url] Hence if you're one of these individuals, you're not alone. In fact, most of us need to lose a few pounds once in a while to get sexy and perfect six pack abs. Now the question is how you are planning to have quick weight loss? [url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips]Quick weight loss[/url] is not like piece of cake. You need to improve some of you daily habbits to achive weight loss in short span of time.

About me: I am author of [url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips]Quick weight loss tips[/url]. I am also health expert who can help you lose weight quickly. If you do not want to go under painful training program than you may also try [url=http://www.weightrapidloss.com/acai-berry-for-quick-weight-loss]Acai Berry[/url] or [url=http://www.weightrapidloss.com/colon-cleanse-for-weight-loss]Colon Cleansing[/url] for quick weight loss.

March 20, 2010 4:46 AM  

~ * ~

Anonymous Anonymous said...

great post, exactly what I was looking for.

Thanks :)

October 08, 2010 1:56 AM  

~ * ~

Anonymous young sister incest stories said...

A tight lipped grunt escaped her set lips, and then a low wavering, open mouthed moan, as the woman squirmed in the flush of rising heat, her eyes closed shut, a dreamy expression on her face, savoring the pleasures of a masterful lovers hands. He asked us to follow him backand then had my wife get up on a table like they would use in ahospital.
hot incest beastiality stories
crossover stories adult
men spanking women stories
office bdsm stories
nifty erotic stories archive lesbian fiction
A tight lipped grunt escaped her set lips, and then a low wavering, open mouthed moan, as the woman squirmed in the flush of rising heat, her eyes closed shut, a dreamy expression on her face, savoring the pleasures of a masterful lovers hands. He asked us to follow him backand then had my wife get up on a table like they would use in ahospital.

December 04, 2010 12:39 AM  

~ * ~

Anonymous Santosh said...

Really Good information. Sir do i find more information on other topics
. Plz let me know sir.

January 13, 2012 5:35 AM  

~ * ~

Anonymous Anonymous said...

buy generic xanax online xanax withdrawal migraine - xanax side effects anxiety

November 16, 2012 1:24 PM  

~ * ~

Anonymous Anonymous said...

irish dating georgia http://loveepicentre.com/testimonials.php dutch reformed dating

January 14, 2013 12:57 PM  

~ * ~

Anonymous Anonymous said...

you're really a just right webmaster. The site loading pace is amazing. It kind of feels that you are doing any unique trick. In addition, The contents are masterpiece. you've
done a wonderful process in this topic!
Here is my weblog games online

January 23, 2013 4:32 AM  

~ * ~

Anonymous Anonymous said...

[url=http://loveepicentre.com/][img]http://loveepicentre.com/uploades/photos/1.jpg[/img][/url]
free gay dating in reading pa [url=http://loveepicentre.com/advice.php]free dating profiles[/url] dating portuguese men
guide to college dating [url=http://loveepicentre.com/map.php]big beautiful women dating minnesota[/url] lonely wives dating club
magic the gathering dating [url=http://loveepicentre.com/]america hollywood dating[/url] horney housewives dating

February 01, 2013 7:51 PM  

~ * ~

Anonymous Anonymous said...

ebook librarian http://audiobookscollection.co.uk/es/The-Language-of-Abuse/p161252/ palm treo ebook reader [url=http://audiobookscollection.co.uk/fr/FreeBSD-6-Unleashed/p106837/]ebook ci ncias[/url] hormones health and happiness ebook

February 13, 2013 9:51 AM  

~ * ~

Anonymous Anonymous said...

boost ebook http://audiobookscollection.co.uk/Teens/c1071/?page=42 types of ebook formats [url=http://audiobookscollection.co.uk/fr/CSS/c2665/?page=2]jo ann ferguson ebook[/url] hellhole ebook

February 15, 2013 1:18 AM  

~ * ~

Anonymous Anonymous said...

free ebook twilight http://audiobookscollection.co.uk/es/Reasoning-Web-Second-International-Summer-School-2006-Lisbon-Portugal-September-4-8-2006-Tutorial-Lectures-Lecture-Notes-in-Computer-Science-Applications-incl-Internet-Web-and-HCI/p209674/ prom secrets ebook [url=http://audiobookscollection.co.uk/Kurt-Jensen/m73591/]brandon sanderson mistborn ebook torrent[/url] cormac mccarthy reader ebook

February 15, 2013 8:41 AM  

~ * ~

Anonymous Anonymous said...

nag hammadi ebook 10.95 http://audiobooksplanet.co.uk/A-Companion-to-Ancient-History/p121904/ free ebook on financial risk manager [url=http://audiobooksplanet.co.uk/authors/?letter=Do&page=3]shock diet gouliaev ebook[/url] ebook catastrophe by dick morris

February 17, 2013 8:53 AM  

~ * ~

Anonymous Anonymous said...

foxe's book of martyrs ebook http://audiobooksworld.co.uk/Yoshiki-Uchikawa/m134822/ libre ebook reader pro reviews [url=http://audiobooksworld.co.uk/Reverte-The-Fencing-Master/p29149/]fonvizin ebook[/url] a rumor of war ebook

February 18, 2013 3:07 PM  

~ * ~

Anonymous Anonymous said...

accounting software and bowling alley http://buyoemsoftware.co.uk/it/product-31554/Slices-1-0-MAC bleem 1.4 demo free software [url=http://buyoemsoftware.co.uk/it/product-37183/Watermark-Master-2-2-Portable]sharp lcd software[/url] paperport 9 software
[url=http://buyoemsoftware.co.uk/es/category-1/Sistemas-operacionales]Sistemas operacionales - Software Store[/url] organization chart free software download
[url=http://buyoemsoftware.co.uk/product-10108/Flaming-Pear-Tesselation-1-35-for-Adobe-Photoshop][img]http://buyoem.co.uk/image/8.gif[/img][/url]

February 27, 2013 8:38 PM  

~ * ~

Anonymous Anonymous said...

[url=http://onlinemedistore.com/products/emsam.htm][img]http://onlinemedistore.com/8.jpg[/img][/url]
sample cvs pharmacy receipt http://onlinemedistore.com/products/femara.htm department 56 foster pharmacy [url=http://onlinemedistore.com/products/valtrex.htm]adzema pharmacy[/url]
anabolic steroids synthroid pravachol actos pet pharmacy http://onlinemedistore.com/products/claritin.htm cvs pharmacy tech starting pay [url=http://onlinemedistore.com/products/antabuse.htm]antabuse[/url]
papermill pharmacy http://onlinemedistore.com/products/aceon.htm jackson pharmacy [url=http://onlinemedistore.com/products/eriacta.htm]quarmby pharmacy long island[/url]
alliance pharmacy belfast http://onlinemedistore.com/products/lasuna.htm buy linezolid zyvox pharmacy [url=http://onlinemedistore.com/products/premarin.htm]premarin[/url]

March 15, 2013 2:25 AM  

~ * ~

Anonymous Anonymous said...

[url=http://onlinemedistore.com/products/plendil.htm][img]http://onlinemedistore.com/4.jpg[/img][/url]
pharmacy sales rep http://onlinemedistore.com/products/himplasia.htm outlook for pharmacy jobs [url=http://onlinemedistore.com/products/zanaflex.htm]spanish words related to the pharmacy[/url]
long term care pharmacy information http://onlinemedistore.com/products/activ8--energy-booster-.htm salary of pharmacy tech [url=http://onlinemedistore.com/products/naprosyn.htm]naprosyn[/url]
av pharmacy http://onlinemedistore.com/products/confido.htm walgreens pharmacy online [url=http://onlinemedistore.com/categories/men-s-health.htm]mississippi board of pharmacy[/url]
fallon pharmacy http://onlinemedistore.com/products/tricor.htm canadian pharmacy citalopram [url=http://onlinemedistore.com/categories/weight-loss.htm]weight loss[/url]

March 15, 2013 12:48 PM  

~ * ~

Anonymous Anonymous said...

[url=http://certifiedpharmacy.co.uk/products/chloramphenicol.htm][img]http://onlinemedistore.com/8.jpg[/img][/url]
lloyds pharmacy independant living for everyone http://certifiedpharmacy.co.uk/products/viagra-jelly.htm can alprazalam be phoned into a pharmacy [url=http://certifiedpharmacy.co.uk/products/estrace.htm]coburns pharmacy in hastings[/url]
cvs pharmacy richmond va http://certifiedpharmacy.co.uk/categories/hypnotherapy.htm pharmacy tech education [url=http://certifiedpharmacy.co.uk/products/rogaine-2-.htm]rogaine 2 [/url]
walmart pharmacy police stings http://certifiedpharmacy.co.uk/products/topamax.htm target pharmacy jobs [url=http://certifiedpharmacy.co.uk/products/kamasutra-ribbed-condoms.htm]channahon ranch pharmacy[/url]
on line universal claim form pharmacy http://certifiedpharmacy.co.uk/products/zithromax.htm colleges with pharmacy [url=http://certifiedpharmacy.co.uk/categories/cholesterol.htm]cholesterol[/url]

April 07, 2013 3:11 AM  

~ * ~

Anonymous Anonymous said...

One trillion cash per year to maintain feeding their growing government's pet tasks. Although, without a doubt, you may be in the position to secure a lower interest rate thus making your own monthly payment decrease, with a consolidating debts book or perhaps a debit credit card. Just about the most important points you need to know possibly be thirty day period, far prior to your salaryday is due. instant payday loans uk may allow you to repair your car and also pay an invoice that is pretty much overdue therefore eliminating overdue charges as well as a hit on your credit rating!

April 07, 2013 3:21 AM  

~ * ~

Anonymous Anonymous said...

With your earnings acting as a sort of guarantee, your payday gets to be an obvious here we are at the lender to build up! You will come across the variety of offers along with advantages - property size the debt should misplace business capital, or financial commitment funds. Such loan providers verify points electronically with out faxing regarding papers becomes necessary. learn more Every state features a college or maybe two which obtains funds through talk about governments in addition to tuition!

April 07, 2013 3:39 AM  

~ * ~

Anonymous Anonymous said...

I'll immediately seize your rss feed as I can not to find your email subscription hyperlink or newsletter service. Do you've any?

Please allow me recognize in order that I could
subscribe. Thanks.

My page: book of raw spielen

May 14, 2013 4:38 AM  

~ * ~

Anonymous Anonymous said...

muq5k43f

sy6nmpz2

f54yewr4t536

ja1j4odw

duxu8b5o

May 20, 2013 3:04 PM  

~ * ~

Anonymous Anonymous said...

Total truth Darcy. They will use significantly far more petroleum planting, harvesting,
processing and transporting the green' gas than they will ever recover in power. Not to point out all of the toxic pesticides they are permitted to use simply because it's not a crop grown for human usage.



my site: complete metabolic cooking package download

June 04, 2013 3:45 AM  

~ * ~

Anonymous Anonymous said...

furry dating yiffstar http://loveepicentre.com/advice/ black hebrew israelite dating site
forensic science carbon dating [url=http://loveepicentre.com/map/]match belgium dating[/url] photos of dating scammers from ghana
who is sean hayes dating [url=http://loveepicentre.com/faq/]milky babe for dating[/url] sucessful dating on signalsnet [url=http://loveepicentre.com/user/sexfish/]sexfish[/url] dating before divorce maryland

June 04, 2013 8:25 PM  

~ * ~

Anonymous Anonymous said...

Your currеnt report providеѕ
proven nеcessaгy tο me perѕonally.
Іt’ѕ really helpful and you rеally are οbviouѕly νerу knowledgeable in this fіeld.
Yοu haѵe popped mу personal ѕight tо bе аble
to ԁifferent thoughts about this topіc along ωіth interesting and ѕound wrіtten content.


My web blοg - Www.Inventati.org

June 05, 2013 7:43 AM  

~ * ~

Anonymous Anonymous said...

We're a group of volunteers and opening a new scheme in our community. Your web site provided us with valuable info to work on. You've
done an impressive job and our whole community will be thankful to you.


Stop by my homepage :: seduction in death robb

June 07, 2013 12:54 AM  

~ * ~

Anonymous Neel said...

Nicely explain..

Please check one more easily understandable concept of parallel cursor.

Parallel cursor easy technique

December 24, 2019 11:18 PM  

~ * ~

Post a Comment

<< Home