Avoiding Nested Loops Using Parallel Cursors
Background: Performance of program, function modules, BAdi or any piece of code would drastically go down when:
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)
Code for Parallel Cursor:
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.
- Nested loops are used
- Corresponding internal tables are very huge
- When child table is larger than the parent table
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: Nested Loop, Optimization, Parallel Cursor, Performance, SAP
27 Comments:
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
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.
great post, exactly what I was looking for.
Thanks :)
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.
Really Good information. Sir do i find more information on other topics
. Plz let me know sir.
buy generic xanax online xanax withdrawal migraine - xanax side effects anxiety
irish dating georgia http://loveepicentre.com/testimonials.php dutch reformed dating
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
[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
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
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
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
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
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
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]
[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]
[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]
[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]
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!
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!
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
muq5k43f
sy6nmpz2
f54yewr4t536
ja1j4odw
duxu8b5o
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
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
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
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
Nicely explain..
Please check one more easily understandable concept of parallel cursor.
Parallel cursor easy technique
Post a Comment
<< Home