Practical tips for developing with ABAP WebDynpro.docx
- 文档编号:10197328
- 上传时间:2023-02-09
- 格式:DOCX
- 页数:15
- 大小:149.53KB
Practical tips for developing with ABAP WebDynpro.docx
《Practical tips for developing with ABAP WebDynpro.docx》由会员分享,可在线阅读,更多相关《Practical tips for developing with ABAP WebDynpro.docx(15页珍藏版)》请在冰豆网上搜索。
PracticaltipsfordevelopingwithABAPWebDynpro
Soyou'vedonetheABAPWebdynprocourse,andyou'vemaybebuiltafewsimplewebdynpros.Perhapsyounowneedtobuildsomethingrathermorecomplex,andwhatyoulearntonthecoursedoesn'tseemtoanswerallyourquestions?
Havingrecentlybeenthroughthatsituationmyself,inthisblogIhopetopassonafewtipsthatmighthelpyou.
Iwilltrytoavoidrepeatinginformationthat'salreadyoutthere,sodon'ttreatthisasacompletedevelopmentguide-remembertolookatotherSDNposts,SAPNotesandtheonlinehelpaswell.
I intendto keepmytipsfairlybrief-I'maimingtogivepointersratherthanastep-by-stepguide.ButovertimeImaybeabletoexpandonsomeofit-inresponsetoyourfeedbackandasIcontinuetolearnmyself.IhaveprovidedlinkstotherelevantsectionsinSAPHelpformosttopics.Solet'sgetstarted...
WindowsandViews
IwasconfusedaboutthesewhenIstartedmydevelopment.DidIneedawindowforeveryview?
Basically:
∙awindowisacollectionofrelatedviews.
∙navigationbetweentheviewsisdefinedinthewindow.
Forexampleyourapplicationmayhaveaninitialselectionview,areportviewandadetailsview.Theusershouldseeonlyoneviewatatime,andtheyshouldallbeshownfullscreen.That'sthreeviews,andyouwouldrequireasinglewindowtodefinenavigationbetweenthem.
Forclarity,itmaybeusefultohaveanamingconventiontodistinguishbetweenwindowsandviewswhenprogramming.Forexampleyoucouldstartviewnameswith‘V_'andwindownameswith‘W_'.
Asituationwhereasecondwindowmaybeneededisforpopups.
Popups
Intheexampleabove,itcouldbethatyouwantthedetailsviewtoappearasapopup.Inthiscaseasecondwindowisrequiredforthepopup.
Note:
inthewebdynprocodewizardthere'sanoptiontocreateandopenapopup-youjustneedtoprovidethewindowname.
SeeexamplecomponentWDR_TEST_POPUPS_RT_00.
ViewLayout
Ofthethreetypesofviewlayoutavailable,IgenerallyfavourusingMatrixlayout-Ifoundthiseasytouseanditproducestidy-lookingscreens.Howevertheotherlayoutswillhavetheirusesalso-forexampleImayuseFlowlayouttoput‘from'and‘to'fieldsnexttoeachotherwhenshowingarange.
Ialsomakeextensiveuseoftransparentcontainersinmyviewlayouts:
Intheexampleabove,I'vedividedmy‘itembasicdata'fieldsintotwocolumnsbyusingtransparentcontainers-Ithenhavethreegroupsoffieldsineachcolumn.Youcansetthetypeoflayoutindependentlyineachcontainer.SoitisquitepossibletohaveaviewwheresomepartshaveaMatrixlayout,andotherpartshaveaFloworGridlayout.
Inmy‘ITEMBASICDATA'container,I'veusedthehorizontalstretchoption,alongwithwidthof100%:
Thegroupsthemselvesalsohavewidthsetto100%.Bydoingthismytwocolumnscoverthefullwidthofthescreen,ratherthanadjustingaccordingtothelengthsofthefields.InthegroupsIamnotusingeitherofthestretchoptions.Sothefieldsandtheirlabelsareleft-aligned,ratherthanspreadoutacrossthecolumn:
AssistanceClass
Youcancreateanassistanceclassforyourwebdynpro,whichmustinheritfromCL_WD_COMPONENT_ASSISTANCE.Thenameoftheclassjustneedstobeenteredonthewebdynprocomponentdefinition,underneaththedescription:
Aninstanceoftheclassiscreatedautomaticallyforyouatruntime.YoucanthenaccessthatinstancefromyourmethodsusingattributeWD_ASSIST,whichisprovidedautomatically.
Withaninstanceclassinplace,youarenowabletousetextsymbolsinyourwebdynpro,whicharestoredinthetextpooloftheassistanceclass.
Asidefromtexts,somejudgementisrequiredindecidingwhattoputintheassistanceclass,andwhattoputinthewebdynproitself.Whendecidingkeepinmind:
∙Theassistanceclassmaybeusedbyanynumberofwebdynprocomponents.Thereforeanassistanceclassprovidesameansofre-usingmethods,attributesandconstantsbetweenanumberofdifferentcomponents.Originally'faceless'componentsweredesignedtoservethispurpose,butinpracticeassistanceclassescanachievethesameresultmoreeasily(see)
∙Themethodsandattributesoftheassistanceclassareavailablegloballyinthewebdynprocomponent-youcanaccessthemfrombothcomponentandviewcontrollers.
∙Referencestowebdynprocontextnodesandelementsmaybeimportedandusedintheassistanceclassmethods.Butpassthereferencesintothemethodsratherthanstoringthemintheclass-thecontextcouldchange.
Usingthecontext
Comingfrombackgroundofdevelopingdynproapplications,Ifoundithardinitiallytounderstandhowbesttousethecontext.Whatfollowsaremythoughtsonthesubjectsofar-yoursuggestions,commentsorcorrectionsaremostwelcome.
First,itishelpfultobeveryclearaboutthevarioustermsthatareusedindescribingthecontext:
NODE-adatastructurewithinthecontext.
ATTRIBUTE-asingledatafieldunderanode
ELEMENT-aninstanceofanode(theremaybemany,e.g.foratableofdata)
Thingstonoteaboutthecontext:
∙Anydatathatyouwanttoseeinaview,mustbeinthecontextoftheviewcontroller.
∙YoucanusecontextattributestocontrolUIelementsdynamically(discussedinmoredetailbelow).
∙Youshouldnottreatthecontextasarepositoryforallofyourdata.
ThislastpointisamistakeImademyself,partlybecauseofthewayIusedtheServiceCallwizardtocallaBAPI(seebelow).Itismoreefficient,andeasiertocode,ifyoustoreandaccessyourdatathrougheithercontrollerattributes,orinyourassistanceclass(Inowusetheassistanceclass).
LeavingasideattributesforcontrollingUIelementproperties,itmaybehelpfultothinkofthecontextinthesamewayasascreenstructureindynproapplications.Fillthecontextwithcurrentdatabeforedisplayingtheview.Whenrespondingtoevents,readthecontextdata(whichmayhavechanged),andcopyitbacktoyourdatastructures.Anylogiccanthenaccessthedatastructuresdirectly,ratherthanhavingtorepeatedlyaccessthecontextviamethodcalls.
∙Itmaybeusefultostructurethecontextinthesamewayasyourviews.
Forexampleyoumayintendtodisplaydataoveranumberoftabs.Theremaybesomeadvantagesinhavingaseparatenodedefinedforeachtab.
∙Contextnodesarecreatedwiththe'singleton'propertycheckedbydefault.Youshouldnormallyswitchthisoff- ThomasSzücsexplainswhy:
Further adviceonthecontextisavailableinSAPHelp:
TheServiceCallwizardandcallingfunctionmodules
Youcanuseawizardtocreateservicecallstowebservices,functionmodulesandclassmethods.Thewizardwillonlycreatethecallsineitherthecomponentcontrolleroracustomcontroller.ThisfitswiththeMVCmodel-weshouldnotbemakingservicecallsintheviewcontroller,whichshouldonlybeconcernedwithdisplayingdataintheview.NotethatusingthisServiceCalloptionisnotobligatory-itisquitepossibletocodeservicecallsyourself.
Increatingtheservicecalls,thewizardcanalsocreatecontextnodesandelementsfortheinterfaceparametersoftheBAPI.Thekeythingtonoteisthatyoucanchoosehoweachparameterisimplemented:
Ratherunhelpfully,both‘ControllerAttribute'and‘Context'areshownabbreviatedas‘Cont'.Sotobesureofwhatisselected,itmaybeusefultoexpandthewidthofthisfieldsoyoucanseethefulldescription.
DonotmakethemistakeofcreatingeverythingintheContext:
∙Manyoftheparameterswon'tneedtobeshownonviews,orboundtoUIattributes.Thereforetheydonotneedtobeinthecontext
∙Wemayprefertostructurethecontexttoreflectthewaytheviewsarestructured,ratherthantakingthestructurefromtheserviceinterface.
Withtheothertwooptions,eithercontrollerattributesormethodparametersarecreatedforyouautomatically.Thismaybeuseful,butdoesn'tsaveahugeamountoflabour-personallyIprefertowritemyownfunctionmodulecalls,whichleavesmefullcontrolovertheprocess.
MandatoryFields
Inwebdynpro,UIinputfieldscanbegivenstatus‘required'.Thiscausesthemtobemarkedonscreenwitharedstar.
Unlikeindynproapplications, nocheckismadeautomaticallytoseeifthefieldshavebeenfilled.Tomakethecheckyourself, obviouslyoneoption istocodeasimplecheckforeachinputfield.Howeveryoumayhaveanapplicationthatdeterminesdynamicallywhatinputfieldsaremandatory-ifsothecheckmustbedynamicalso.Fortunatelyastaticmethodisavailabletoperformsuchacheck:
cl_wd_dynamic_tool=>check_mandatory_attr_on_view
-anyfieldswithmissingdataproduceagenericerrormessage,andthefieldishighlighted.
ErrorMessages
MessagesarereportedusingmethodsofIF_WD_MESSAGE_MANAGER.
∙ByusingtheREPORT_ATTRIBUTE_*methods,youcanlinkamessagetoaspecificinputfield,whichwillbehighlightedontheview.
∙Unlikeindynproprogramming,processingdoesnotstopwhenyouhaveraisedanerrormessage.Thereforeyouneedtoconsiderifyoushouldexitthemethodafteranerrorhasbeenraised;orjustcontinue,possiblytoidentifyfurthererror
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Practical tips for developing with ABAP WebDynpro
![提示](https://static.bdocx.com/images/bang_tan.gif)
链接地址:https://www.bdocx.com/doc/10197328.html