Documente Academic
Documente Profesional
Documente Cultură
procedure
3
DEVELOPMENTTOOLS,PL/SQL
BYVICTORONNOVEMBER12,2010
Sharethison..
13
Introduction
WithinApExforawhileithasbeenpossibletocreateapage(morespecifically,aform)basedonaprocedure.Aprocedureenablesyoutobuildinmorelogicthana
simpleDMLstatementorotherwise.MyexampleisrelativelysimpleinthatwhenIwanttobookanappointmentwithsomebody,Idonotwantthisappointmentto
overlapwithsomebodyelses.MaybeIevendontwantmyappointmenttobedirectlyafterorbeforeanotherone,andwanta15minutebreak.
Scenario
Buildtheprocedure
Thiskindofscenarioisnoteasytorealiseifyoudonthaveaplan.TheplanisthereforetobuildanINSERTstatement(intoaprocedure,notafunction!)thatisonly
actuallyexecutedwhenthereisenoughroomformynewappointmentintermsoftimeinmyagenda.BuildingthisprocedureisdoneintheObjectBrowserareaof
Apex(Home>SQLWorkshop>ObjectBrowserpressCreate).
Tocheckthatthereareactuallynooverlapsyouneedtoknowwhentheappointmentstartsandhowlongitwilltake.(Loadsmoreadditionalfeaturescouldbeadded,I
amtryingtokeeptheexamplesimplefornow).Thisjustifiesatleast2INparametersforaproceduretobebuilt,startingmomentanddurationoftheappointment.
Anotherparameterwillbeusedtoreturntheanswer.Thisanswermustbeofatextualcharacter(!),sayingsomethingalongthelinesofYourappointmentwas
successfullyenteredintoyouragenda,orYourplannedappointmentisoverlappingwithanother.Allowforatleastenoughcharacterstoholdthismessage,asan
OUTparameterinyourprocedure.Theprocedurecouldlooksomethinglikethis
Notetheuseoftheparametersatthetopandwhatpurposetheyserve.TheOUTparameterispopulatedwithaninformativemessagethatwillappearintheformthat
westillhavetobuild.
Buildthepage
Thenextstepwouldbetobuildthepage.Itisobviousthatyouneedtotestinsomewaythattheprocedureworks.Thereforerelevanttablesandreferencedatamust
beavailable.
Movetotherelevantapplicationandcreateyourpage.ThereforepresstheyellowCreatepagebutton.
ThenselectFormandpressNext.
ThenselectFormonaprocedureandpressNext.
Youarepromptedtoselecttheschemaowneroftheproceduretobeused.PressNext.
Thenextscreenenablesyoutoselecttherelevantprocedurefromalistofvalues.Whatisslightlymisleadingisthatthelistofvaluesalsodisplaysfunctions,
whichinthiscontextareofnouse,sadly.SelecttherequiredprocedureandpressNext.
Thenapagedisplayswith7entries,ofwhichthecompulsoryentriesaredepictedwithanasterisk:
Adefaultpagenumberisdisplayed.Youcanmodifyit,ifyouhavethoughtupyourownpagenumberingsystem.Itisacompulsoryentry.
Defineapagename,equallycompulsory.
Definearegiontemplate.Youcanleavethisasisfornow.
Thenextentry,regionname,isalsocompulsory.Makethisanexplanatorypieceoftext,asitwillappearontopoftheregion.
ThenexttwoentriesenableyoutoenterSubmitandCancelbuttonlabels.Youmayprefertodisplaylabelsinanotherlanguage.
Thefinalentryenablesyoutochoosetohaveabreadcrumbdisplayedatthetopofyourpage.Leavethisvalueasis.
PressNext.
YouwillbepresentedwithascreenthatenablesyoutoselectaTab(existentornow)ornotabatall.Fornowleavethistothedefaultsetting,andpressNext.
Nextyouwillseeascreenquotinganoptionalinvokingbutton.Thisisanextrabuttonthatwillbecreatedsomewhereelseinyourcollectionofpageswithinthe
application,thatenablesyoutomovetothepagethatwearecurrentlymaking.Thepagewhereyouwantthisbuttontobecreatedcanbedefinedinthefirst
entry,forwhichalistofvalidvaluesisavailable.
Inthesecondentryyoucansimplytypethelabelforthisbutton.Shouldyouleavethese2entriesemptythennosuchbuttonwillbecreated.
Fornowwewillnotdoanysuchthingyet.
PressNext.
ThenextscreenenablesyoutodefinewhichpagestomovetowhenyoueitherpresstheSubmitorCancelbuttons.Pleasedefinetwopages,makinguseof
theofferedlistofvalues.Youmayevendecidetousethesamepageforthetwodifferentbuttons.PressNext.
Nowyouarepresentedwithascreenthatmakesuseoftheparametersthatweredefinedfortheprocedureinvolved.
Hereyoucanseequotedthe3namesoftheparameters,forwhichyoucanmodifythelabels(thenamesthatappearintheformyettobegenerated).Namesin
theexamplestartwithD,likethenamesoftheparametersthemselves.The3settingsIncludeshouldbeleftsettoYes.IntheDefaultentryyoucansetdefault
values.Thevaluestobeentereddependonthetechnicalfunctionalityoftheprocedure.Iftheproceduretakescareofdefaultvaluesthentheapplicationdoes
notneedtodoso,andviceversa.NotethatinthisscenariodatesofdatatypeDateareinvolved,beingD_START_DATUM.Forall3itemstheDisplay
TypemaybekepttoText.
PleasenotethattheD_BERICHTparameteraccordingtotheprocedurewillcontainamessagethatcanbeusedintheapplication.
PressNext.
YouwillbepresentedwithaFormonProcedureconfirmation.PressFinish.
YouwillbegiventheoptionsofRunningorEditingthepage.Wearesoanxiousnow,sopressRunPage.
Somethinglikethiswillbepresentedtoyou:
Afewmorepointsneedtobeaddressedbeforetheformwillactuallyworkproperly:
Thisishardlyaformthatyoucanpresenttoauser.Toatleastmakeitabitmorepresentablegivetheuseracalendardisplaytype(thiswouldhavetoinclude
thetime,notjustthedate)whendatesneedtobeentered.
Adefaultvaluefortheminutes(thisisthenumberofminutesthatanappointmentwouldtake)couldbesetat60or90.
TheD_MESSAGEcanbeleftempty.Theprocedureshouldusethistofillinanappropriatemessage.
ThepreviouswarninginthistextsayingthatwearedealingwithdatatypeDATE(namelyD_START_DATUM)wewillhituponnow.Achangeinoneofthe
processesismandatoryforthisformtowork.
Finallythenamesofthefieldsandtheformsneedtobemodified.
Toaddresstheseissuesweneedtodothefollowing:
Press
EditPagexx
,inmyparticularcaseitwaspage13.Ascreenverysimilartothiswillappear:
InthePageRenderingbox:RightclickonP13_START_DATUM.
PressEdit.
IntheNamebox,setDisplayastoDatePicker.
IntheLabelbox,adjusttheLabel,byremovingthetrailingD.
IntheSettingsbox,setFormatMasktoDDMONYYYYHH24:MI(usethelistofvalues).
PressApplychangesinthetoprightofthescreen.
SimilarstepsfortheMinutesentrycanbeexecutedtocheckthatthereisadefaultvaluedefined.
WhenyouarebackinthescreenwherePageRenderingisatthetop,rightclickonRunStoredProcedureunderneaththePageProcessingheaderand
selectEdit.
Modifythecodeasfollows,notingthatitisacalltothepreviouslydefinedprocedure,whichneedstobeadjustedsothatthedata(namelydataof
typeDATE)isdealtwithproperly:
#OWNER#.P_ENTER_PLANDATE(
D_START_DATUM=>TO_DATE(:P13_START_DATUM,'DDMONYYYYHH24:MI'),
D_MINUTEN=>:P13_MINUTEN,
D_BERICHT=>:P13_BERICHT);
PressApplyChanges.
PressRunPage,andcheckthatthefunctionalityiscorrect.
Conclusion
WecanconcludethattherearemanythingsinApexthatcanberealised,butsometimesApexneedssomehelpfromus.ThemodificationinthecodethatApexmade
foruswasnotsufficientforittoworkproperly.Whenbuildingcodeyouwillfindmoreoftenthatyouareremindedofthefactthatyouareactuallytryingtobuildan
applicationfortheinternet,andthatbrowsersdontreallytakedatatypesoftypedate(andprobablyothersalso)intoconsideration.
Thetextinthisblogisbynomeanscomplete.Itismerelytryingtoinspirepeopletouseinthiscaseformsforaprocedure.Pleasedonothesitatetoleaveany
comments,feedbackoradditionstothetextofferedtoyou.Thankyouforyourattention.
Sharethison..
13
Relatedposts:
1.CreatinganXMLTypebasedonObjectTypes
2.CreatingashuttleboxinApex
3.OracleSQLandPL/SQL:jugglingwithuserdefinedtypes(ADT)andXMLTypeforcreatinganADTbasedXMLServiceAPI
4.ShouldyouexposeaStoredProcedureviaXMLType?
5.APEXpluginscontributedtotheAPEXcommunitybyAMISdevelopers