Вы находитесь на странице: 1из 2

3/9/2017 ABAPCodeforParallelCursorLoopProcessingCodeGallerySCNWiki

GettingStarted Store

CommunityWIKI SAPCommunity Welcome,Guest Login Register SearchtheCommunity


CodeGallery

ABAPCodeforParallelCursorLoopProcessing
CreatedbyGuest,lastmodifiedbyManishKumaronJun19,2013

Author:KarthikCSunil
Submitted:18Aug2007
RelatedLinks:

http://karsap.blogspot.com/2007/06/avoidingnestedloopsusingparallel_19.html
http://karsap.blogspot.com/2007/06/improvedversionofparallelcursor.html

Abstract
Thispagewillexplainhowtocodeveryefficientlyfornestedunrelatedtables.Thearticledescribeshowtoimprovetheperformanceofprocessinghugedataamounts.

ProblemDescription
ThemostcommonperformanceproblemthatoccursinABAPprogramsisbecauseofhugenumberofrecordsintheinternaltables.Theproblemcomplexifiesifaprogramhashugenestedinternaltables.
Howmucheverefficientdataselectroutinesare,dataprocessingroutineswouldbecontributingsignificantlyforthebadperformance.Whenanalyseditwouldberevealedthatthewhereconditionthatis
usedininnerloopsexpendasignificantamountofprocessingtime.Theideaistoavoidwhereconditionsintheinnerloopsbymaintainingtheloopindexesmanually.

ConventionalCodefornestedloops
Errorrenderingmacro'code':Invalidvaluespecifiedforparameter'lang'

loopatlt_vbpaintowa_vbpa.
loopatlt_kna1intowa_kna1wherekunnr=wa_vbpakunnr.

******YourActuallogicwithininnerloop******

endloop.
endloop.

Codesample:ParallelCursormethod
Errorrenderingmacro'code':Invalidvaluespecifiedforparameter'lang'

sort:lt_vbpabykunnr,"Sortingbykeyisveryimportant
lt_kna1bykunnr."Samekeywhichisusedforwhereconditionisusedhere
loopatlt_vbpaintowa_vbpa.
readlt_kna1intowa_kna1"Thissetsthesytabix
withkeykunnr=wa_vbpakunnr
binarysearch.
ifsysubrc=0."Doesnotentertheinnerloop
v_kna1_index=sytabix.
loopatlt_kna1intowa_kna1fromv_kna1_index."AvoidingWhereclause
ifwa_kna1kunnr<>wa_vbpakunnr."Thischeckswhethertoexitoutofloop
exit.
endif.

******YourActuallogicwithininnerloop******

endloop."KNA1Loop
endif.
endloop."VBPALoop

StaticalAnalysis
NestedloopforBSEGandBKPFinternaltableswereanalysedforConventionalMethodandParallelCursormethods.Followinggraghexplainstheobservations.

https://wiki.scn.sap.com/wiki/display/Snippets/ABAP+Code+for+Parallel+Cursor++Loop+Processing 1/2
3/9/2017 ABAPCodeforParallelCursorLoopProcessingCodeGallerySCNWiki

Observation:Onecanobservethatasthedataincreases,thetimetakenforthenestedloopincreasesdrastically,atthesametime,theParallelcursormethoddidnotsufferanyconsiderabletimeimpact.

Verdict:Usetheparallelcursormethodwheneverthereisaneedtoprocessdatainanestedloop.
snippet abap parallel cursor performance

1Comment
CSPBhat
1)Iamnotsureifthesortontablelt_vbpaisrequiredatall.

2)SE30DocumentationtalksaboutO(n1+n2)runtimeforaparallelcursoralgorithm.

Thedocumentationextract:

NestedloopsDocumentation
IfITAB1hasn1entriesandITAB2hasn2entries,thetimeneededfor
thenestedloopwiththestraightforwardalgorithmisO(n1*n2),
whereastheparallelcursorapproachtakesonlyO(n1+n2)time.
TheaboveparallelcursoralgorithmassumesthatITAB2containsonly
entriesalsocontainedinITAB1.
Ifthisassumptiondoesnothold,theparallelcursoralgorithm
getsslightlymorecomplicated,butitsperformancecharacteristics
remainthesame.

HoweverforthecodegivenhereitisO(n1*logn2).Surelyitsafarmoreefficientalgorithm
comparedtooriginalnestedloopwithO(n1*n2)runtime.BUT,IamnNotsureifthisis
theintendedparallelcursoralgorithm.whichissupposedlyO(n1+n2)

ContactUs SAPHelpPortal
Privacy TermsofUse LegalDisclosure Copyright FollowSCN

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

Вам также может понравиться