第7章练习.docx
- 文档编号:4331694
- 上传时间:2022-11-29
- 格式:DOCX
- 页数:15
- 大小:334.91KB
第7章练习.docx
《第7章练习.docx》由会员分享,可在线阅读,更多相关《第7章练习.docx(15页珍藏版)》请在冰豆网上搜索。
第7章练习
ABAPCourse
Chapter7:
ABAPObjectsandBusinessServerPages
Content
Thischapterexplainsthemainconceptsofobjects-orientationandtheiradaptioninABAP.FurthermoretheconceptofBusinessServerPages(BSPs)isexplainedandaswellasrelatedtopicsliketheuseofBAPIs,HTMLBandtheModel-View-Controllerpattern.
Prerequisites
YoushouldbefamiliarwithABAPandthenavigationintheSAPsystem.
Motivation
ThischapterexplainshowtocreatesimpleprogramsinABAPObjects.FurthermoreitshowshowtomaintainandexecuteBSPapplications,howtouseaBAPIwithinaBSPandhowtodesignBSPsusingHTMLB.Abovethat,thischapterexplainshowtoadapttheModel-View-ControllerpatternforBSPs.
Lecturenotes
ThefundamentalunderstandingoftheABAPdevelopmentintheSAPsystemisaprerequisiteforthestudents.Studentscangoonwiththeiraccountfromchapter1.
▪Product:
All
▪Level:
Beginner
▪Focus:
Programming
▪Version:
1.0
▪Author:
UCCTechnischeUniversitätMünchen
Task1:
LoginintotheSAPsystem
Shortdescription:
UseSAPGuitologinintotheSAPsystemwithyourusernameandpassword
Login
StarttheSAPGuiandloginintothedevelopmentsystemusingtheprovidedaccountandpassword.Pleaserefertochapter1foryourusernameandyourpassword.
Task2:
WorkingwithABAPObjects
Shortdescription:
UsetheconceptofABAPObjectwithinanABAPprogram.
PleasestarttheObjectNavigatorfromtheSAPEasyAccessMenubyusingthefollowingpath:
Menupath
Tools•ABAPWorkbench•Overview•ObjectNavigator.
YoumayalsousethetransactioncodeSE80fordirectaccess.
NoTOPINCL
Createanewprogramnamed‘ZY_##_OBJECTS’.DonotuseaTOP-Includeanddeclaretheprogramastestprogram.
Youwillcreateanewlocalclasswiththepurposeofsavingairlines.Thisclasswillbecalledintheprogramandseveralnewinstancesofthisclasswillbecreated.
Firstaddcommand‘INCLUDEZY_##_CLASS_INCLUDE.’inyourprogramandcreatethecorrespondingincludeprogrambytheuseofforwardnavigation(doubleclick).ThenewlycreatedincludeprogramwillincludedefinitionandimplementationofthelocalclassLCL_AIRPLANE.
Declaremethods
Pleasestartwiththeclassdeclaration.Yourequireamethodset_attributesandamethodget_attibuteswithpublicaccess.Methodset_attributeincludesanimportingparameterim_namefortheairplanenameandimportingparameterim_planetypefortheairplanetype.Bothattributeshavetobedefinedintheprivatesectionasattributes.ThedeclarationofthelocalclassisshowninFehler!
Verweisquellekonntenichtgefundenwerden..
Implementation
Methodset_attributesshouldprovidefunctionalitytosetbothprivateattributesnameandplanetypeaccordingtotheimportingparameters.Methodget_attributesshouldprovidefunctionalitytooutputtheattributevaluesforacertainobjectwithhelpoftheWRITE-command.TheImplementationofbothmethodsisshownhere:
Pleasereturntothemainprograminordertoimplementtheuseoftheclass.Youwillnowcreateseveralairplanesusingareferenceandsavethereferencesontheseobjectsinaninternaltable,inordertoaccesstheseobjectsagainatalaterdate.Thereferencer_planewilluseanewtypedefinition:
ItwillrefertothelocalclassLCL_AIRPLANEbytheuseofTYPEREFTO.Inthesamewayinternaltableit_plane_listisdefinedastableofreferencesonthislocalclass.Thedatadeclarationofprogram‘ZY_##_OBJECTS’thereforelooksasshowninthefigurebellow:
Nowstarttheblock‘START-OF-SELECTION’bycreatinganobjectwithcommandCREATEOBJECTthatisreferencedbyvariabler_plane.Callmethodset_attributeusingthisreferenceandassignnameandplantypetothenewobjectusingthecorrespondingparametersofthemethod.Appendthereferencetotableit_plane_listusingthecommandAPPEND.Byappendingthereferencetheaddressofthecreatedobjectissavedinthetableandthereferencer_planeitselfcanbeusedforotherobjects.Nowcreateanewairplaneandappendthisreferencetotheinternaltablesaswell(compareFehler!
Verweisquellekonntenichtgefundenwerden.).
Createtwoobjects
Finallyyouwillloopattheinternaltableanddisplaydataforeachairplaneonthescreenusingmethodget_attribute.
Loopthroughthelist
Pleasesave,checkandactivateyournewprogram.Finallytestit.Youshouldseetheattributesofbothcreatedobjects.
Task3:
CreateasimpleBusinessServerPage(BSP)
Shortdescription:
CreateanewBSPApplication.
PleasestarttheObjectNavigatorfromtheSAPEasyAccessMenubyusingthefollowingpath:
Menupath
Tools•ABAPWorkbench•Overview•ObjectNavigator.
Openyourpackage
YoumayalsousethetransactioncodeSE80fordirectaccess.
Openyourpreviouslycreatedpackagebyselectingtheentry‘Package’fromthedropdownlistandtypeinthenameofyourpackage.Pleasehit‘Enter’.
CreateBSPapplication
CreateanewBSPapplication‘ZY_##_BSP’usingthepathCreate•BSPLibrary•BSPApplicationofthecontextmenuofyourpackage.Inthepop-uptypeinthenameofyourBSPapplicationandmaintaintheshorttext.
BSPLibrary
Assignallnewlycreatedobjectstoyourpackageandtransportrequest.SaveyournewBSPapplication.InyournavigationtreeanewnodeBSPLibraryisshownnow.YoucanfindyourBSPApplicationwithinthesubnodeBSPApplications.
Newpage
Createanewpagenameddisplay.htmusingthecontextmenuofthisapplication.IntheareaPageTypepleaseactivateradiobutton‘Pagewithflowlogic’.
InsertHTML
Switchtothetab‘Layout’inordertodisplayyournewpage.Deletethealreadygeneratedsourcecodecompletely.NowentertheserversidelanguagethatwillbeusedfortheBSP:
inthiscasetheserversidelanguageisABAP.CreatewithcommonHTML-Codeanewpageandenteratitleofyourchoice.Insertadatadeclarationforaninternaltableandaworkareareferringtotable‘SPFLI’inABAP.Thedeclarationshouldbeembracedbythetags<%and%>.FurthermoreaddaSELECT-statementthatmovesallflightconnectionsoftableSPFLIintointernaltableit_flights:
Loop
NextcreateaHTMLtable.ThefirstrowofthetableincludestheheadlinesforAirline,FlightConnection,DepartureairportandtimeaswellasArrivalairportandtime.FurtherrowsofthetablewillbecreatedusingaLOOP-statementontheinternaltable‘it_flights’.
Save,check,activate
Save,checkandactivatetheapplication.AssoonasyoustarttestingthepageanewwebbrowsersessionisopenedandyouhavetologinwithyouruserID.Theresultshouldlooksimilartothis:
如果网页打开失败,则试验如下的网址:
http:
//uccwdisp2.fit.qut.edu.au:
1088/sap(bD1lbiZjPTEwMA==)/bc/bsp/sap/zy_teach03_bsp1/display.htm
并将上述的蓝字部分替换成你自己的BSPApplication的名称,将黄字部分替换成你自己的Page名称
Task4:
UseofBAPIsinBusinessServerPage(BSP)
Shortdescription:
UseaBAPIinyourBSPapplicationtoaccessdatafromanotherSAPSystem.
PleasestarttheObjectNavigatorfromtheSAPEasyAccessMenubyusingthefollowingpath:
Menupath
Tools•ABAPWorkbench•Overview•ObjectNavigator.
YoumayalsousethetransactioncodeSE80fordirectaccess.
Newpage
ForthistaskuseagainyourBSPApplicationZY_##_BSP.Createanewpagenamedcall_bapi.htmusingthecontextmenuofyourapplication.IntheareaPageTypepleaseactivateoptionPagewithflowlogic.
Deletesomecode
Afterconfirmationofthedialogscreenyouaredirectedtothe‘Layout’tabofthenewBSPpage.Firstofallpleasedeletesomecodelinessoyoursourcecodelookssimilartothis:
BAPIBrowser
AsyoucanseewearealreadyusingHTMLBforthispage.ButastherehavebeennoHTMLB-specificelementsinuseyet,wedonotregardHTMLBanyfurtherinthisstep.
NowyouwanttoincludetheBAPIcall.Forthisstepyouneedtofindout,whichimportandexportparametersarerequiredfortheBAPIcall.ThereforeswitchtotheBAPIBrowserusingthemenupathGoto•BAPIBrowser.
IntheBAPIbrowserscrolldowntillyoufindnode‘V25’.TheseshownnodesaresocalledRFCconnections(remotefunctioncalls),whichareusedbytheSAPsystemtotransferdatabetweenSAPsystemsandalsototransferdatatoitself.Openthenode‘V25’please(thismaytakealittlewhile)andscrolldowntillyoufindtheBAPI‘BAPI_USER_GET_DETAIL’.TheBAPIislocatednearlyattheendofthelist.
BydoubleclickingonittheSAPsystemopensthedescriptionandthecallexamplesfortheBAPI.YouwanttousetheBAPItogetanswersabouttwoquestions:
▪Whenwastheuser‘xyz’lastchanged?
▪Istheuseraccountlocked?
Callfunction
ABAPcode
TocalltheBAPIinyourBSPyouhavetoperforma‘CALLFUNCTION’andtoexporttheRFCconnectionaswellastoexportparameterse.g.ausername.Theincomingdatafromthefunctionwillbestoredintemporaryvariables.ThefollowingsnippetshowsyoutheABAPcodeofyourpage.PlacetheABAPcodebeforetheHTMLBcode:
TheABAPcodedoesthefollowing:
atfirstyoudefinesometemporaryvariables,thencalltheBAPIbyusingthecallfunctioninstructionandthenconvertthereceivedresultsintoauseableformat(thisisdonebytheifinstruction).Nowyouhavetodefinesometextfieldtodisplaytheresults.Theentiresourcecodeofyournewprogramshouldlooksimilartothis:
Entiresourcecode
Result
Save,checkandactivateallofyourobjects.Testthelittleexample.Theresultsshouldbesimilartothis:
YoumaywanttotestsomeotherfeaturesforthetextfieldsandsomeotherBAPIs.Pleasefeelfreetodoso.
Task5:
TakeadvantageofHTMLB
Shortdescription:
UseHTMLBtodisplaytheresultofaSQLstatementusingoneHTMLBinstruction.
Intask4youusedtheusua
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 练习
![提示](https://static.bdocx.com/images/bang_tan.gif)