extending a cics web application using jcics · • fundamentals of using the jcics api ... in the...

24
Extending a CICS Web application using JCICS This course provides Java application developers with a guide to CICS services, demonstrating how to access them using the JCICS API. Topics covered include: Fundamentals of using the JCICS API Using JZOS to map native record-based language structures to Java data types Communicating with other CICS programs using a COMMAREA LINKing to a Java application deployed in Liberty Accessing CICS resources, for example VSAM and temporary storage queues Managing unit of work scope in Java Handling errors in Java Students should be familiar with the concepts and techniques discussed in "Developing a RESTful Web application for Liberty in CICS" before taking this course. http://www.redbooks.ibm.com/abstracts/crse0302.html?Open

Upload: others

Post on 17-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

ExtendingaCICSWebapplicationusingJCICS

ThiscourseprovidesJavaapplicationdeveloperswithaguidetoCICSservices,demonstratinghowtoaccessthemusingtheJCICSAPI.Topicscoveredinclude:

• FundamentalsofusingtheJCICSAPI• UsingJZOStomapnativerecord-basedlanguagestructurestoJavadatatypes• CommunicatingwithotherCICSprogramsusingaCOMMAREA• LINKingtoaJavaapplicationdeployedinLiberty• AccessingCICSresources,forexampleVSAMandtemporarystoragequeues• ManagingunitofworkscopeinJava• HandlingerrorsinJava

Studentsshouldbefamiliarwiththeconceptsandtechniquesdiscussedin"DevelopingaRESTfulWebapplicationforLibertyinCICS"beforetakingthiscourse.

http://www.redbooks.ibm.com/abstracts/crse0302.html?Open

Page 2: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

Section1Lecture1HelloandwelcometotheCICSJavacoursetoextendaCICSwebapplicationusingtheJCICSAPI.MynameisIanBurnettandI’mpartoftheCICSdevelopmentteam,basedintheIBMHursleylabintheUK.

ThiscoursewillshowyouhowtoextendyourknowledgeofJavadevelopmentinCICS,inordertoproducefeature-richapplicationsthatusearangeofCICSfeatures.

Wewillbuilduponknowledgegainedinthe“DevelopingaRESTfulWebapplicationforLibertyinCICS”course,anduseyourexistingdevelopmentenvironmenttoproducemorecomplexJavaapplications.

WewillstartthecoursebylookingatthefundamentalconceptsyouneedtounderstandasaJavadeveloperwheninteractingwithCICS.Usingthesefundamentals,wewillcreateasimplepieceofcodetoinvokeCICSprogramsfromtheLibertyenvironment.

AfterwehaveunderstoodtheprinciplesofinvokingotherCICSprogramstomanipulatedata,wewilllookatseveralresourcesavailableinCICSandstudytheAPIsusedtointeractwiththoseresourcesdirectlyfromJava.

AnotheraspectofCICSapplicationsisthattheyadheretotheACIDpropertiesofatransaction,andtheabilitytodelineateresourceupdatesintounitsofworkisalsoavailabletoJavaapplications.WewilllookathowCICSprovidesunit-of-worksupport,andalsohowthatfitswiththeJCICSAPI.

Developingapplicationsthatareenterprise-ready,requiresrobustprogrammingpracticestogracefullyhandleapplicationandsystemerrors.OurfinaltopicwillbetocovertheconceptsandpracticalitiesofhandlingerrorconditionsusingJava.

OurcodesamplesareavailablefromtheCICSdevGithubrepositoryandprovidefully-workingexamplesofusingtheJCICSAPIsthatwewillbediscussing,alongwithadditionalsupportingmaterial.

TherepositoryshowncontainsmanyJavasourcefilesthatusetheJAX-RSinterface,inordertoprovideasimplemechanismofinvokingJavacodeinaCICSenvironment.AlltheexamplesusetheHTTPGETverb,andreturnJSONdata.RESTfulapplicationswouldtypicallyuseavarietyofHTTPverbs,howeverthesamplecodeisnotintendedasareferenceforthedevelopmentofRESTfulapplications,butmerelytoalloweasytestingusingasimplewebbrowser.

Duringthiscourse,wewillassumethatyouhaveaLibertyJVMserverrunninginCICS.ThesamplecodeprovidedrequiresuseoffacilitiesdefinedbytheJAX-RSspecification,thereforeyourLibertyserver.xmlfileshouldbeconfiguredtoincludethisfeature.

WewillalsoassumeyourworkstationisconfiguredwithadevelopmentenvironmentthatcontainsthenecessaryJCICSJavalibraries.Adynamicwebprojectissufficienttopackagethecodesamples,andforsimplicity,theLibertydrop-insdirectorycanbeusedfordeployment,althoughCICSbundlesmaybeusedifrequired.

Refertothe“DevelopingaRESTfulWebapplicationforLibertyinCICS”courseifyouneedfurtherinformationonconfiguringJavainyourCICSenvironment.

Thank-youforwatchingthiscourse.

Page 3: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

Section2Lecture1TheabilityforprogramswrittenindifferentlanguagestocommunicateandshareresourceswhilstrunningasasingletaskisakeystrengthofCICS.AswediscussedinapreviouscoursetheinterfacetoaCICSprogramisdefinedusingeitheraCOMMAREA,orChannelsandContainers.

DifferentlanguagesdefinethelayoutoftheCOMMAREAorcontainerusinglanguagespecificstructures.

TheClanguageallowsfieldstobedefinedwithdatatypessuchascharacters,integersandfloatingpoints.

COBOLprogramsdefinestoragelayoutusingfields,representedbypictureclauses,tospecifythedifferentnumericandcharacterdatatypes.

UsuallytheselanguagestructuresareseparatedoutintoasourcefilereferredtoasacopybookinCOBOL,orasaheaderfileintheClanguage.Inpracticalterms,acopybookoftenrepresentsanentitysuchasanemployeeorastockitem.

Aswellasdescribinginterfaces,alanguagestructurecanalsobeusedtodescribethelayoutofdatastoredinsequentialrecordssuchasVSAMfilesorTemporaryStorageQueues.

TointerfacewithexistingprogramsfromJavaweneedameansofaccessingdatawithinstructuredrecords.

WhenusingtheJCICSAPItolinktoaCICSprogramCOMMAREAdataispassedasabytearray.

UsingthestandardJavalanguageconstructs,itispossibletoconstruct,populate,andreadfromthisbytearraydirectly.However,thereareseveralproblemswiththisapproach.

Firstly,manualbytearraymanipulationistimeconsumingtodevelopanderrorprone.

Secondly,arecordmaycontainanelementinaformatthatisnotnativelysupportedbythestandardJavalibraries.Forexample,packeddecimalfieldsarecommononz/OS,buthavenoJavadatatypeequivalent.

Finally,manipulationofindividualbyteswithinabytearraydoesnotfitverywellwiththeobject-orientedprogrammingmodelofJava.

ThesolutiontotheseproblemsistogenerateaJavabeanfromthecopybookwithaccessormethodswhichgetandsetthefieldsautomaticallyconvertingdataasrequired.

Thegeneratedbeanprovidesamappingbetweentheobject-orientedJavaprogrammingmodel,andtherecordorientatedprogrammingmodel.

Wewillcoverthegenerationofthesebeansinafollowinglecture.

Duringthiscourse,itwillbeusefultouseasamplecopybooktodemonstratehowandwherebytearraysareusedintheJCICSAPI.

ThesamplematerialsprovideanexampleCOBOLcopybookthatdefinesseveralfieldsinan80-byterecord.

Therecordrepresentsanentryinastockwarehouse.Inourapplication,afileisusedtoholdthousandsoftheserecords,representingthetotalstockinventoryforawarehouse.

Page 4: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

AsweexploretheJCICSAPIinthiscourse,wewillbeusingthesamplerecordtodemonstratecommunicationbetweenvariousapplicationcomponents.

Lookinginmoredetailatthe80-byterecorddefinedinthesample,wecanseeseveralfields.

Firstly,an8-bytefieldisusedasthepartID,itrepresentstheuniquekeyforthisrecordwithinthestockdatabase.NotwopartswithinthedatabasehavethesamepartID.

Asecond8-bytefieldisusedtorepresenttheIDofthesupplierofthatpart.Thiswouldlikelyreferenceanentryinanotherfile,whichcontainedalistofallthesuppliersused.

Eachparthasaunitprice,thatisdefinedusingthepackeddecimalformat.

Twodatesarestoredintherecord–thelasttimeanorderwasplaced,andthenexttimeanorderwillbeplacedforthispart.

Anumericfieldcontainsinformationaboutthenumberofthesepartsthatarecurrentlyheldinthewarehouse.

Finally,adescriptionofthispartisstoredinthesecondhalfoftherecordintextformat.

Thesupportingmaterialcontainsanothersamplecopybooktorepresentasupplier.Thiswillbeusefullaterwhendemonstratingcaseswhererelationshipsexistbetweenrecords.

Inthenextlecture,wewilllookattheJZOStoolkitandhowtherecordgeneratorcomponentcanbeusedtomapfromoursampleCOBOLcopybooktoanobject-orientedJavaclass.

Page 5: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

Section2Lecture2JavarecordsareusedtomapnativerecordbasedlanguagestructurestoJavadatatypes.IBMsuppliestwoJavarecordgenerationtools.

OneoptionistheJ2CrecordimporterprovidedwithIBMDeveloperforzSystemsEnterpriseEditionwithintheJ2Cfeature.

TheotheroptionistheJZOSRecordGeneratorwhichwewilldescribeinthiscourse.

TheJZOSrecordgeneratorcreatesaJavaclass,basedonacopybookfromCOBOLoraDSECTfromassembler.Inourexample,wewillgenerateaJavaclassfromthestockpartcopybookthatwelookedatinthepreviouslecture.GeneratingaJavarecordisatwo-stageprocess.

ThefirststageistocompiletheCOBOLprogramspecifyingtheADATAparametertogeneratetheADATAfile.

ThesecondstageistoruntheJZOSrecordgeneratorusingtheADATAfileasinput,togenerateaJavasourcefile

TheJavasourcefilecanbeincludedinajavaprojectorcanbecompileddirectlyintoaJavalibrary.

IncludingthegeneratedJavasourcefileintheJavaapplicationprojectisusefulwhenthegeneratedcodeneedsfurthercustomizationsuchaschangingencodingsforspecificfields.TodothatrequiresimportingthegeneratedJavasourcefileintoyourEclipsedevelopmentenvironment,andthenaddingtheJZOSlibrarytotheprojectbuildpath.However,iftheCOBOLcopybookchangesandrecordneedstoberegenerated-thiswillrequiredevelopmentefforttoupdatethesourceintheEclipsedevelopmentenvironment.

AnalternativeapproachistocompilethegeneratedsourcefileandpackageitintoaJavaarchive,orjarfile,whichcanbeincludedwiththeJavaapplication.ThisuseofacompiledjarfileavoidstherequirementtoaddtheJZOSlibrariestotheEclipseworkspaceandallowsmultiplerecordstobepackagedwithinasinglelibrary.AnotheradvantageofthisapproachisthatitcanbeautomatedandtheJARfileplacedinarepositoryfordependencymanagement.

Thesampleapplicationthataccompaniesthiscoursefollowsthe“compileandJAR”approach.Itsuppliesalibraryjarfilecontainingacompiledrecordclassthatcorrespondstothestockpartcopybook.

Inthissection,wehavelookedathowtheinterfacetoCICSprogramscanbedefined,andhowJavaapplicationscanuserecordgeneratorstomaptothisinterface.WethenshowedhowtheJZOSrecordgeneratorcouldbeusedtobuildaJavarecordfromthecompilerADATA.Finally,weshowedhowtopackagetheJavarecordintoalibraryfordistributiontodevelopers.

Inthenextsection,wewilllookatusingthisgeneratedrecordwhenlinkingtoaCICSCOBOLprogramfromaJavaapplication.

Formoredetailsonthesesteps,includingaworkedexamplewithcompleteJCL,havealookatthe“BuildingJavarecordsfromCOBOLwithIBMJZOS”ontheCICSdevelopercenter.

Thankyouforwatching.

Page 6: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

Section3Lecture1Inthe“DevelopingaRESTfulWebapplicationforLibertyinCICS”course,welookedattheconceptofaCICSprogram.

Aprogramisaunitofcompiledcodethatprovidesapplicationlogic,andcanbedevelopedusingoneofmanylanguagessupportedintheCICSenvironment,includingJava.

TheterminologyusedwhencallingfromoneCICSprogramtoanotherisknownasalink.Thelinkcommandpassescontroltothetargetprogramandwaitsforittocomplete.

AlinkdiffersfromaJavamethodcallinthatthetargetprogramcanbeimplementedinanylanguagesupportedbyCICSandcanalsoresideonadifferentCICSsystem.

AJavamethodcallhoweverisconsiderablymorelightweightthanalinkcommand

WhenusingtheJCICSAPI,firstcreateaninstanceoftheProgramclass,andspecifythenameofthetargetprogramusingthesetName()method.

Toissuethelinksimplyinvokethelinkmethodontheprogramobject.Herewedonotpassanyargumentsonthelinkmethodsonodataispassedtothetargetprogram.

Whencommunicatingfromoneprogramtoanother,therearetwomainwaystopassdata---eitherthroughtheuseofacommarea-orthroughtheuseofchannelsandcontainers.

Nowlet’slookatpassingacommareaonalinkcommand

Acommareaisanareaofmemoryusedtopassdatabetweentwoprograms.

FromaCICSperspective,acommareaisjustasequenceofbytes,CICSdoesnotattempttoformatthedatastructureandjustfacilitatesthetransferofthedatabetweentheprograms.

Thedatastructureisdescribedusinganinterface,wherethefieldsaredefinedusingalanguagespecificstructuresuchasaCOBOLcopybookaswediscussedinthepreviouslecture.

ForaJavaapplicationtocommunicatewithanapplicationwritteninanotherlanguagewecanuseabytearraytorepresentthecommareaandtoholdthedatatobetransferred.Asnotedintheprevioussection,generatedJavaclassescanbeusedtomoreeasilyconstructtherequiredbytearray.

Inthisexample,welookatpassingasinglerecordfromourJavaapplicationintoanexistingCICSprogramusingtheCOMMAREAinterface.Thisrecordisdefinedbythestandardstockpartrecordformatcoveredearlier.

WhenusingtheJZOSrecordgeneratortooling,wecalledourgeneratedclass“StockPart”.So,ourfirsttaskistocreateaninstanceofthisclass,andpopulateitwithrelevantdata.

TheJZOSrecordgeneratortoolingdefinesgetterandsettermethodsintheJavaclass,thenamesofthesemethodscorrespondtothefieldsoftheoriginalCOBOLcopybook.

GetterandSettermethods,otherwiseknownas“accessor”methods,allowaJavadevelopertouseanobject-orientedapproachwhenbuildingarecord.

Page 7: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

OncetheJavaobjecthasbeeninstantiated,wecanconvertitintoabytearrayusingthegetByteBuffer()method.Thisreturnsaserializedversionofthestructuredrecorddefinedintheoriginalcopybook.

Nowthatwehavethedataready,wecanusethistolinktothetargetprogram.

WecreateanewinstanceoftheProgramclass,andspecifythenameofthetargetprogramthatwewishtoLINKtousingthesetName()method.

Wetheninvokethelinkmethodonourprogramobject-thistimepassingtheStockPartbytearray

Onsuccessfulreturnfromthetargetprogram,anyupdatestothecommareawillbereflectedinthebytearray.

Here,wetaketheupdatedbytearrayandconstructanewStockPartobjecttorepresentthereturneddata.Subsequentcodemaythenreadvaluesfromthisnewly-constructedobjectusingtheaccessormethods.

Acommareaisabidirectionaltransfermechanism,andprogramscanusethisareatosendanyformatofdataineitherdirection.OurpreviousexamplesentarecordintheStockPartformat,andreceivedarecordinthesameformat.

Withalargeenoughdataarea,anyrecordformatcanbereturned.

Inthisexample,weuseaStockPartobjecttoconstructabytearraythatwillbepassedtoatargetprogram.Whencalled,thatprogramwilllookupthesupplierrecordandpopulatethecommareawitharecordformatdetailingthesupplierofthatpart.

HavingpreviouslycreatedasuitableJZOSclasstomaptherecordforasupplier-whenthelinkmethodcompletes-wecangenerateanewinstanceofthesupplierobjectfromthereturnedbytearray.Theresultingobjectcanbequeriedforthesupplierinformation.

CICSoffersanoptimizationonalinkcommandbyspecifyingthesizeofthedatatothetargetprogram-abenefitalsoavailablefromtheJCICSAPI.

Asanexample,apartlookuproutinemayonlyneeda8-bytepartnumberasinput,butwillrequirean80-bytecommareatoreturnthedata.Specifyingtheoptionalintparameterafterthebytearrayallowsthecallertospecifythedatalengthusedonthesend.

Inthisexample,abytearrayoflength80iscreatedbythecallingprogram,butthedatalengthisspecifiedas8.WhenCICSpassescontroltothetargetprogram,onlythefirst8bytesaretransmitted.Theremainderofthe80-bytecommareaispaddedwithzeroes.Whenthetargetprogramreturns,all80-bytesaresentbacktothecallingprogram.

ThisoptimizationcanbeusedtoreduceCPUandresponsetimes,especiallywherelargecommareasarerequiredforreturnvaluesorwherelinksflowbetweenCICSsystems.

RecallthattheothermethodofpassingdatafromoneprogramtoanotherisbyChannelsandContainers.Achannelisaconduitbetweenprograms,ittypicallyholdsoneormorecontainerstobepassedbetweentheprograms.Acontainerisanamedblockofdata.

Channelsandcontainersoffertheadvantagethatmorethan32KBofdatacanbepassed.Bycontrast,commareasareconfinedtoa32KBlimit.

Page 8: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

Multiplecontainerscanbepassedbetweenprogramswithinachannel.Achannelisthereforeanalogoustoaparameterlist.

AworkedexampleofusingchannelsandcontainersinJCICSisavailableinthe“DevelopingaRESTfulWebapplicationforLibertyinCICS”course.Thesamplematerialsforthiscoursealsocontainanexampleofusingchannelsandcontainerstopassdata.

ThislecturehaslookedatthewaysinwhichtheJCICSAPIcanbeusedtoLINKtoanotherCICSprogram.

ThesamplesourcecodeprovidedwiththiscoursehasexamplesofalltheJCICScommandscoveredinthislecture.

ThenextlecturewilllookathowwecanlinkfromaCICSprogramintoaJavacomponentinaLibertyJVMserver

Page 9: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

Section3Lecture2WebSphereLibertyprovidesaJavaEnterpriseEditionorJavaEEplatform,andisdesignedtohelpdeveloperscreatelarge-scaleenterpriseapplications.

UsingLinktoLiberty,anyCICSprogramcannowcallJavaEEapplicationsinaLibertyJVMserver.

TheCICSLINKcommandcaninvokePlainOldJavaObjects(POJOs)thathavebeendeployedinsideaWebapplication...justasiftheywereanyCICSprogram.

ToachievethisseamlessLINK,aCICSdefinedJavaannotationisappliedtoaJavamethodwithintheLibertyapplication.TheannotationindicatesthatthemethodshouldbeexposedastheentrypointforaCICSJavaprogram

WhentheapplicationisinstalledCICSwilldetecttheannotationmeta-dataandautomaticallycreateandinstallaPROGRAMresourceforeachentrypointdetected.

OncethesePROGRAMresourceshavebeencreated,thenaCICSapplicationwritteninanylanguagecanusetheLINKcommandandinvokethedesiredJavamethodpassingachannelastheinterface.Notethatacommareacannotbepassedinthisscenario.

Inthisexample,wehaveaclassorPOJOinaWebapplicationthatexposesthegetSupplierInfo()methodasanentrypoint.The@CICSProgramannotationisusedtoindicatethismethodshouldbemadeavailableasaPROGRAMresource.Whentheapplicationisinstalled,aCICSprogramresourcenamedGETSUPPLisautomaticallycreated,andisreadytobeinvoked.

DataispassedbetweencallingprogramandtheLibertyapplicationusingChannelsandContainers.

WithinthetargetJavamethod,JCICSisusedtogetareferencetothecurrentchannelandtoobtainthedatafromcontainersprovidedbythecaller.

Oursamplecodeprovidesacompleteimplementationofthegetsupplierinfomethod.ThesamplecodecouldbeextendedtouseJavaEEcapabilitiessuchasJAX-RSclientAPItorequestinformationfromasupplierusingaremote,RESTfulwebservice.

FromtheperspectiveofthecallingCOBOLapplication,ithasusedtheCICSLINKcommandtoinvokeanamedprogrampassingindataviaacontainer,andreceivedaresponseusingaCOBOLstructure.

ThePOJOcomponentinthewebapplicationwasabletoreceiveandprocessthecontainersandexploitJavaEE7functionality.

Inthissection,wehavelookedathowwecanlinktootherCICSprogramsusingmethodsontheJCICSProgramclass.

Usingourgeneratedrecord,wepasseddatatoexistingCICSapplicationsusingthecommareainterface.Thealternativemethodofpassingdatabetweenprograms-theCICSchannelsandcontainerssupport-wascoveredinthe“DevelopingaRESTfulWebapplicationforLibertyinCICS”course.

Finally,welookedathowCICScanmakeLibertyapplicationsavailabletotraditionalprograms,usingtheLinktoLibertycapability.

Inthenextsection,wewilllookathowtoaccessotherCICSresourcesusingtheJCICSAPI.

Page 10: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

Section4Lecture1CICSprovidesaccesstoarangeofresourcetypes.SomeoftheseresourceslikeTemporaryStorageQueuesareuniquetoCICS,whileotherssuchasVSAMfilesarecommonacrossz/OS.Inthissection,wewillbelookingataccessingtheseresourcesusingtheJCICSAPI.

We'llcometotheCICS-specificresourcesshortly,butfirstlet’sstartwithVSAMfiles.

InCICS,datamanagementservicesaretraditionallyknownasCICSfilecontrol.CICSfilecontroloffersyouaccesstodatasetsthataremanagedbytheVirtualStorageAccessMethod,orVSAM.

Basicdirect-accessmethod,orBDAM,datasetsarenotsupportedbytheJCICSAPI,sothislecturewillfocusonVSAMfiles.

CICSfilecontrolletsyouread,update,add,delete,andbrowsedatainVSAMdatasets.YoucanalsoaccessCICSshareddatatablesandcouplingfacilitydatatablesusingthefilecontrolAPIs.

FilesmaybesharedbyapplicationswithinaCICSregion,oracrossthewiderz/OSsysplex.

ACICSapplicationprogramreadsandwritesitsdataintheformofindividualrecords.EachreadorwriterequestismadebyaCICScommand.

Toaccessarecord,theapplicationprogrammustidentifyboththerecordandthedatasetthatholdsit.

Thereareseveralmethodsthatcanbeusedtoidentifyarecord–whichonetousedependsonthetypeofVSAMfileinuse.WewilllookatthedifferenttypesofVSAMfilelater.

AnapplicationusesaCICSfileresourcetoidentifyadataset.ThisfileresourcehasauniquenamewithintheCICSregion,allowingtheapplicationtoremainagnosticoftheunderlyingdatasetname.

Itisnotnecessaryforanapplicationtoopenorcloseafileexplicitly,CICSmanagestheresourceonbehalfofallapplications.

Inthisdiagram,anapplicationaccessesaVSAMfileusingCICSfilecontrol.

TheapplicationidentifiesthedatasettobeusedbyreferencingtheCICSFILEresourcenamedSTOCK1.

TheSTOCK1fileresourceisdefinedtoreferencetheMVSdatasetTESTdotDATAdotSTOCK.

Theapplicationcouldlaterbedeployedintoadifferentsystem,whereafileresourceofthesamenamereferencesadifferentMVSdataset.

CICSsupportsaccesstothefollowingtypesofVSAMdataset:

• Key-sequenceddataset,orKSDS• Entry-sequenceddataset,orESDS• andRelativerecorddataset,orRRDS

Akey-sequenceddatasethaseachofitsrecordsidentifiedbyakey.Thekeyofeachrecordisafieldinapredefinedpositionwithintherecord.Eachkeymustbeuniqueinthedataset.

Anentry-sequenceddatasetisoneinwhicheachrecordisidentifiedbyitsrelativebyteaddressoroffset.

Arelativerecorddatasethasrecordsthatareidentifiedbytheirrelativerecordnumberororder.

Page 11: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

TheVSAMdatasetstopicintheIBMKnowledgeCenterhasamorecomprehensivedescriptionofthesedifferentVSAMdatasets.

Ourexamplewilluseakey-sequenceddataset.

BeforewecanuseVSAMfiles,weneedtodefinethedatasetusingthez/OSutilityIDCAMS.

TheexampleshowssomesampleinputtotheIDCAMSutilitytodefineaVSAMfilenamedTEST.DATA.STOCK.WewillusethisdatasetinourexampletostorestockinformationfromtheStockPartrecordwegeneratedusingJZOSearlier.

Therecordskeywordindicatestheamountofspacethatthedisksubsystemneedstoreserveforthedataset,whiletheINDEXEDkeywordspecifiestheVSAMdatasetistobeusedforkey-sequenceddata.

TheKEYSkeywordspecifiesthateachrecordhasauniquekeythatiseightbytesinlengthandbeginsatoffsetzero.ThismatchestheSTOCKPARTrecordwedefinedearlier.

Finally,theRECORDSIZEkeywordspecifiesthatonaverage,eachrecordwillbeeightybytesinlength,withamaximumlengthofeightybytes.WhileVSAMfilessupportvariable-lengthrecords,oursimpleapplicationonlyusesfixed-lengthrecords.

Forthefullexample,seetheaccompanyingsampleprojectmaterialsinGithub.

Asdescribedearlier,aCICSapplicationisabstractedfromthephysicaldatasetsitusesbymeansofaCICSFILEresource.Inordertouseoursampleapplication,youwillneedtodefineandinstallaFILEdefinitionintotheCICSregion.

Forthisexample,mostofthedefaultswillbesuitable,withsomeexceptions.

Thefileresourcedefinitionrequiresanameofuptoeightcharacters–thesamplecodeusestheSMPLXMPLname.

IfyoudonotspecifythefileasaDDstatementinyourCICSstartupjob,youwillneedtospecifythephysicaldatasetnameusingtheDSNAMEattributeonthedefinition.

TofullydemonstratetheJCICSfilecontrolAPI,youshouldsetalloftheadd,browse,delete,read,andupdateattributestoyes,otherwiseCICSwillthrowanexceptionwhentheapplicationattemptstoperformanoperationthatisnotpermitted.

NowwearegoingtodevelopthewebapplicationtoaccesstheVSAMfile.

ThesampleclassVSAMKSDSfileresourceprovidesanumberofmethodstodemonstratethevariousaspectsofaccessingaVSAMfile.

Thesimplestofthesemethodsisthe“writenewrecord”methodwhichcreatesanewstockpartandaddsittotheVSAMfile.

Aswiththeexamplesinthe“DevelopingaRESTfulWebapplicationforLibertyinCICS”course,weuseasimpleRESTfulinterfacetoinvoketheJavacode.

TheCICSApplicationclassspecifiesabaseapplicationpathof“rest”,thereforeanyRESTfulresourcesaccessedinthiswebapplicationwillusethisstringasarootURI.

Page 12: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

TheVSAMKSDSfileresourceclassspecifiesarelativeresourceURIofksdsusingthePathannotation,whilethewritenewrecordmethodspecifiesapathof“write”relativetotheparentresource.

Forthewritenewrecordmethod,wewouldthereforeusetheURI“rest/ksds/write”relativetothebaseURIoftheapplicationwheninstalledintoCICS.

OnlytheHTTPGETverbisrecognizedinthisapplication,asindicatedbytheGETannotationonthemethod.

ThewritenewrecordmethodreturnsaStockPartCollectionobject,whichisserializedtoJSONasdirectedbytheProducesannotationontheclass.TheStockPartCollectionobjectisasimplewrapperobjectthatcontainsalistofStockPartobjects.

TocreatearecordsuitableforinsertionintotheVSAMfile,thegeneratemethodinthestockparthelperclasscreatesaninstanceoftheJZOS-generatedStockPartclassandpopulatesitwithsampledata.

ThewritenewrecordmethodtakesthegeneratedrecordandconvertsthistoabytearrayusingtheJZOSgetbytebuffermethod.

Anothermethodinthestockparthelperclassextractstherecordkeyasabytearray.Recallthatthekeyforthestockpartrecordiseightbytesinlengthandbeginsatoffsetzero.ThehelperclassobtainsthebytearrayfromtheStockPartobjectandextractsthefirsteightbytesasanewbytearray.

Inthisexample,weareaccessingakey-sequenceddataset,orKSDSfile.ToreferencethisfileusingJCICS,wecreateaninstanceoftheKSDSclassandspecifythenameoftheCICSfileresource.

ThewritemethodontheKSDSclasstakestwobytearraysasparameters–thekeyandtherecordforwriting.

TheCICStransactionwouldautomaticallybecommittedonnormalcompletionoftheCICStask,butasasimpledemonstrationofmanagingunitsofwork,thesampleapplicationusestheTaskcommitmethodtoexplicitlycompletethecurrentunitofwork.

Finally,thequeryfilemethodisinvoked,whichreturnsaninstanceofthestockpartcollectionclass.

Thequeryfilemethodperformsafilebrowseoperation,startingattheveryfirstrecordinthefile,andreadingeachrecordintomemory.Eachrecordisconvertedtoastockpartobjectandaddedtothestockpartcollectioninstance.WhenserializedtoJSON,thisprovidesasimplemeansofviewingthecontentsofthesampleVSAMfileandhowitisaffectedbyeachfilecontroloperation.

Forclarity,thenecessaryerror-handlinglogichasnotbeenincludedhere,butisprovidedinthesamplecode.Wewillcovererror-handlinglaterinthecourse.

TheupdateRecord()methodprovidesanexampleofupdatingarecordinaVSAMfile.

Firstly,theKSDSfileisreferencedbycreatinganewinstanceoftheKSDSclass,aspreviouslydoneinthewritenewrecordmethod.

Toreaddatafromafile,arecordholderobjectisrequired.ThereadforupdatemethodontheKSDSclassisthencalled,passinginthreeparameters.

Page 13: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

ThefirstparameteristhekeyoftherecordthatwewishtoreadfromtheVSAMfile.Inthiscase,wesupplyakeyofallzeroes,createdusingamethodinthestockparthelperclass.Akeyofallzeroesisusedinourapplication,simplytoobtainthefirstrecordintheabsenceofrealdata.

Thesecondparameterspecifiesthattheapplicationwillreadtherecordwithakeyequalto,orgreaterthan,thekeysupplied.

Thefinalparameteristherecordholderinstance,whichwillbeusedtoreceivethedatathatresultsfromtheVSAMfilereadoperation.

Onsuccessfulcompletionofthereadforupdatemethod,therecordholderinstancewillcontainabytearrayrepresentingtherecordinthedataset,aslocatedbythespecifiedkey.Thegetvaluemethodextractsthisbytearray,anditispassedtotheconstructorofthegeneratedstockpartclass.

Asecondstockpartinstanceiscreatedusingthegeneratemethodwecoveredearlier.Thepartid,orkey,fromthereadrecordiscopiedintothenewly-generatedrecord.Thisstepisusedasasimpledemonstrationofwherebusinesslogicwouldamendvaluesinareal-worldapplication.

WethenupdatetherecordintheVSAMfilebycallingtherewritemethod,supplyingthefullrecordasabytearray.

Notethatforarewriteoperation,wedonotneedtosupplythekey,asthiswasestablishedonthepreviousreadforupdateoperation.

Finally,weexplicitlycallthetaskcommitmethodtoreleaseanylocksweholdagainstthefile.

Whenexecutingthesamplecode,repeatedlyaccessingtherest/ksds/updatemethodbypressingrefreshinyourbrowserwillshowthefirstrecordinthefilebeingupdatedwithnewsampledata.

ThedeleterecordmethodintheVSAMKSDSfileresourceclassprovidesanexampleofdeletingarecordinaVSAMfile.

Theflowofthemethodisverysimilartotheupdaterecordexample,withareadforupdateoperationfindingthecorrectrecord,andthenthedeletemethodbeingcalledtodeletetherecordfromthefile.

Inthislecture,wehavelookedathowwecanusetheJCICSAPItoaccessVSAMKSDSfiles,usingourgeneratedJZOSclasstoprovideanobject-orientedmeansofaccessingstructuredrecordsondisk.ManyoftheconceptscoveredhereareequallyapplicabletoESDSandRRDSfiles.SeetheJCICSJavadocdocumentationforacompletereferenceonthesyntaxrequiredtoaccessthesetypesofVSAMfiles.

Inthenextlecture,wewilllookathowJavaapplicationscanaccessCICStemporarystoragequeues.

Page 14: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

Section4Lecture2

CICStemporarystoragequeues,orTSQs,areameansofstoringasequenceofdataitems.

DatainaTSQcanbestoredinmainmemory,ondisk,knownasauxiliaryTSQs,orsharedviathesysplexcouplingfacility.

ThedataitemsinaTSQhaveamaximumsizeofjustunderthirtytwokilobytes,andcanbeaccessedinanyorder

TSQsarereferencedusinganameofupto16charactersinlength.Theycanbedefinedasbeingrecoverableornon-recoverableCICSresources.

Temporarystoragequeuesdonotneedtobedefinedinadvanceofanapplicationusingthem,andcanbeusedtosharedataacrossapplications.

SupportfortemporarystoragequeuesisprovidedintheJCICSAPIbyusingtheTSQclass.

InoursampleweareusingaTSQfromwithinaCICSLibertyWeb-applicationandbecauseHTTPrequestsarestateless,we'llneedsomemeansofpersistingtheTSQnameacrossmultipleHTTPrequests.

Toprovideasimple-to-usemethodofaccessingthesametemporarystoragequeuefromabrowseracrossmultiplerequests,thequeuenameisstoredinanHTTPsessionobject.

EverytimeabrowserissuesaGETrequestagainstthetemporarystorageresourceclass,thegetqueuemethodextractsthequeuenamefromtheHTTPsessionobject,andreturnsaJCICSTSQobjectthatcorrespondstothecorrectqueueforthatbrowsersession.

Examiningtheflowinmoredetail,thefirsttimeabrowseraccessesthesampleapplication,itissuesanHTTPGETrequestagainsttherestslashtsqslashwriteURI,andhasnocookietokentosendtotheserver.Thegetqueuemethodintheapplicationfindsnocookiehasbeensent,andhencenoHTTPsessionispresent.

Thegeneratequeuenamemethodisinvokedtocreateanew,uniquequeuename.ThisqueuenameisstoredinanHTTPsessionobject,whichispersistedautomaticallybytheLibertyruntime.

Page 15: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

Thewritenewrecordmethodwillwriteanelementtothisnewqueue,andthenreturntotheclient.WhentheLibertycontainersendstheJSONresponsebacktothebrowser,italsoincludesanHTTPsessioncookieaspartoftheflow.

SubsequentrequestsfromthebrowserwillflowthisHTTPsessioncookietotheapplication,andthiscookieisusedbytheLibertyserverasakeytoretrievetheHTTPsessionobjectthatcorrespondstothebrowserinstancemakingtherequest.

BeforeweexaminetheJCICSAPIindetail,let’stakeabrieflookatsomeofthesamplecode’shelpermethods.

Thenameofthequeueusedbyoursampleapplicationiscreatedbythegeneratequeuenamemethod.Thiscreatesaqueuename,basedonaknownprefixandthecurrenttime.

ThesampletemporarystorageresourceclassprovidesexamplesofaccessingaTSQusingtheJCICSAPI,

Thewritenewrecordmethoddemonstrateshowtowriteasingleelementtoatemporarystoragequeue.

HereweusethegetqueuemethodtoobtainaninstanceoftheJCICSTSQclass.

ThisTSQobjectreferencestheCICStemporarystoragequeuethatisinusebythecurrentbrowsersession,usingthemechanismdescribedearlier.

AsamplerecordiscreatedusingthestockparthelperclasswecoveredwhenlookingatVSAMfileaccess,andabytearrayisobtainedusingtheJZOSgetbytebuffermethod.

WritingasingleelementtoaTSQisachievedbysimplycallingthewriteitemmethod,passingthedatatobewrittenasabytearray.

InasimilarmannertotheVSAMexamples,astockpartcollectionobjectisreturnedbythemethod,andisserialisedbytheLibertyserverasaJSONresponse.

Page 16: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

Thiscollectionobjectiscreatedbythequeryqueuemethod,whichperformsabrowseacrossthequeue,addingeachqueueelementtothecollection.

Therearetwoimportantpointstonotefromthequeryqueuemethod.

Thefirstisthatelementsinatemporarystoragequeuearenumberedfromelementone,unlikemanyconstructsyoumaybeusedtoinJava.

ThesecondisthatitemsarereadfromaTSQusinganItemHolderinstance.ThisitemholderobjectperformsasimilarfunctiontotherecordholderwediscussedearlierforVSAMfiles.

AsinthepreviousVSAMexample,theupdaterecordmethodwillupdatethefirstelementinthequeue.

ThegetqueuemethodisagainusedtoobtaintheTSQcorrespondingtothecurrentbrowsersession,andanewsamplestockpartrecordiscreatedusingthestockparthelperclass.

TheTSQisupdatedthroughtheuseoftherewriteitemmethodintheTSQclass,whichtakestwoparameters–theitemindexandthenewdatatowritetothequeue.

Afterupdatingthequeue,ourqueryqueuemethodiscalledtoreturnthecontentsofthequeueasaJSONresponse.

Individualelementscannotbedeletedfromatemporarystoragequeue–itisonlypossibletodeleteanentirequeue.

ThedeletemethodintheTSQclasstakesnoargumentsanddeletesthecorrespondingtemporarystoragequeue.

ThedeletequeuemethodinoursamplecodegivesasimpleexampleofobtainingaTSQobjectandthendeletingtheunderlyingqueue.

Inthislecturewehavecoveredthebasicconceptsofatemporarystoragequeue,andlookedathowwecanusetheJCICSAPItoaccessthesequeuesfromJava.

Thankyouforwatching.

Page 17: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

Section4Lecture3

Oneofthefundamentalconceptsoftransactionprocessingisthatresourceupdatesadheretotheatomicity,consistency,isolation,anddurabilityprinciples,commonlyknownastheACIDpropertiesofatransaction.

Resourcesaccessedbyaprogramaremanagedwithinatransactionalscopeknownasaunitofwork.AllrecoverableresourcesaccessedwithinasingleunitofworkareupdatedaccordingtotheACIDprinciples.

Aunitofworkmayeithercompletesuccessfully,knownasacommit,orunsuccessfully,knownasarollback.

InaCICStask,anactiveunitofworkisalwayspresent.

AunitofworkbeginsautomaticallyatthestartofaCICStask,beforecontrolispassedtotheapplication.UponsuccessfulcompletionofaCICStask,theunitofworkisautomaticallycommitted.

IfaCICStaskterminatesabnormally,thentheactiveunitofworkisrolled-backandanyupdatestorecoverableresourcesareundone.

UpdatestorecoverableCICSresourcesmadefromJavaapplicationswillbesubjecttothesameunitofworkconstraintsasotherCICSprograms.

Itisalsopossibleforanapplicationtomangetheunitofworkboundaries.

TheJCICScommitandrollbackmethodsintheTaskclasscanbeusedtocompletethecurrentunitofworkandupdateresourcesaccordingly.

OncethecurrentunitofworkhasbeencompletedinCICS,anewunitofworkisautomaticallycreated,ensuringthatanyresourceupdatesalwaysoccurwithinaunitofwork.

Wherelargenumbersofresourcesarebeingupdatedinlong-runningtasks,iftheapplicationdesignpermits,itisrecommendedthatunitsofworkarecommittedperiodically.Thiswillreducethenumberofoutstandinglocksthatareheldbytheapplication,andpotentiallyimproveoverallsystemthroughput.

Page 18: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

ThewritenewrecordmethodinourVSAMsampleshowsanexampleofexplicitlycommittingthecurrentCICSunitofwork.

Inthissection,wehavelookedatthecharacteristicsofseveralCICSresources,andhowtoaccessthemusingtheJCICSAPI.

InthislecturewecoveredtheCICSsupportforunitsofwork,andhowapplicationscancontrolthescopeofupdatestorecoverableresources.

Inthenextsection,wewilllookathowJavaapplicationscansuccessfullyhandleapplicationandsystemerrors,inordertoproducemorerobustapplications.

Oursampleapplicationcodeprovidesexamplesofaccessingkey-sequencedVSAMfiles,CICStemporarystoragequeues,andalsoCICStransientdataqueuesusingJCICS.

Thankyouforwatching.

Section5Lecture1

Itisimportanttoprovidegooderror-handlinglogicinenterprise-classsoftwaretogracefullyhandlearangeofapplicationandsystemproblems.

Inthissection,wewilllookathowJavahandleserrorsingeneral,thenapplythatknowledgetotheJCICSAPI.

Duringexecutionofanapplication,variouserrorconditionsmayarise.Theseerrorconditionsmayhavemanyrootcauses,butfundamentallytheycanbecategorisedintothreemaintypes:expectederrors,unexpectederrors,andfatalerrors.

Expectederrorsareconditionsthatcanbereasonablyforeseenbyanapplicationdeveloper.Forexample,attemptingtoreadanon-existingrecordfromaVSAMfileislikelytobeaconditionthattheapplicationisexpectedtohandle.

Unexpectederrorsareconditionsthatmayoccur,butarenotnormallyexpectedtobehandledbytheapplication.Forexample,aprogrammayattempttoaccessanelementofaJavaarraywhichdoesnotexist.Thisprobablyrepresentsaprogrammingerror,andasaresult,theapplicationislikelytobeinanindeterminatestate.

Page 19: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

Fatalerrorsarethemostseriousofallerrorconditions,andusuallyrepresentasituationfromwhichanapplicationisunlikelytobeabletorecover.AnexampleofafatalerroroccurringwouldbeiftheJavavirtualmachinefailedtoloadaJavaclassrequiredbyanapplication.

ErrorconditionsintheJavalanguagearemanagedusingtheexceptionmechanism.

IfaJavamethodencountersanerrorcondition,thenaspecialJavaobjectcalledaThrowableiscreatedtocapturethestateofthecurrentthreadatthetimeoftheerror,andthisobjectispropagatedtothecallerofthecurrentmethod–aprocessknownasthrowinganexception.Correspondingly,handlingtheerrorconditionisknownascatchinganexception.Acallingmethodusesatrykeywordtoindicatethescopeoftheerrorhandlinglogic.

TheJavalanguagespecifiesthattheobjectsusedwhenpropagatingexceptionsmustbeinstancesofatypewhichextendstheThrowableclass.TheThrowableclassitselfhastwodirectsubclasses–ExceptionandError.Therearemanysub-classesofException.However,theRuntimeExceptionsubclassisaspecialcaseandisnotclassifiedasacheckedexceptionasitrepresentsunexpectedruntimeerrors.

Together,thecheckedexception,runtimeexception,anderrorclassesrepresenterrorconditionsinJavacodethatcorrespondtotheexpected,unexpected,andfatalerrorcategoriesthatwecoveredearlier.

InJava’serrorhandlingmechanism,expectederrorsextendtheExceptionclass,andareknownascheckedexceptions.

TheJavalanguagespecifiesthatanymethodwhichcanthrowacheckedexceptionmustdeclarethisaspartofthemethodsignature,usingthethrowskeyword.

AnyJavacodewhichcallsamethoddeclaredasthrowingacheckedexceptionmusteitherprovidelogictocatchthecheckedexception,oraddtheexceptiontoit’sownmethodsignature,inordertopropagatetheexceptionfurtherupthestack.

Theconstraintsoncheckedexceptionsareenforcedatcompiletime,andfailuretoadheretothespecificationwillresultinacompilationerror.

UnexpectederrorconditionsarerepresentedbyJavaclasseswhichextendtheRuntimeexceptionclass,andareknownasuncheckedexceptions.

Uncheckedexceptionsarenotsubjecttothecompiletimecheckingmandatedforcheckedexceptions,althoughtheycanbecaughtifrequired.

Page 20: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

FatalerrorconditionsarerepresentedbyJavaclasseswhichextendtheErrorclass.ItisconsideredpoorprogrammingpracticetocatchanyexceptionsthataresubclassesoftheErrorclass,astheserarelyrepresentaconditionfromwhichtheapplicationwillbeabletorecover.

NowletstakealookathowCICSerrorhandlingismanagedforCOBOLandotherhighlevellanguages.

TheselanguagesthatusetheEXECCICSAPIhavethreechoiceswhenhandlingerrorconditions:onaper-commandbasis,usingaconditionhandler,orusinganabendhandler.

IfaCICScommandproducesanerror,thenitwillfirsttrytoreturnaresponsecodetotheapplicationusingthedataareasuppliedintheRESPparameteroftheCICScommand.

IfaRESPparameterhasnotbeensupplied,thenCICSwillsearchforanactiveconditionhandler.ConditionhandlersareregisteredinadvanceusingtheEXECCICSHANDLECONDITIONcommand,andperformsomeformofapplication-specificrecoveryoperation.

Ifnoactiveconditionhandlerisfound,thenCICSwillabnormallyend,orabendthetask.TherearemanytypesofCICSabendsdefined,eachcorrespondingtoaspecificerrorcondition,andabendsareclassifiedbytheirfour-characterabendcode.

Whenanabendoccurs,CICSwillsearchforanactiveabendhandlerthatmatchesthegeneratedabend.Similartoconditionhandlers,anabendhandlerroutineisregisteredinadvanceusinganEXECCICSHANDLEABENDcommand.

Ifanactiveabendhandlercannotbelocated,thenCICSwillabnormallyterminatethecurrenttask,whichinturnwillrollbackanyuncommittedupdatestorecoverableresourcesinthecurrentunitofwork.

NowletsconsiderhowCICSerrorsmaptotheJCICSAPI.

TheJCICSexceptionhierarchyincludesuncheckedexceptions,checkedexceptions,andfatalerrors.

Page 21: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

ThekeytothemappingbetweenCICSerrorsandtheJCICSexceptionhierarchyisunderstandingwheretheseexceptionscouldbethrown,howtheymaptotheCICSresponsecodes,andwhatactionyoushouldtakeasanapplicationdeveloper.

Let'sstartbylookingatcheckedexceptions.

HereweseethekeyclassesinvolvedintheJCICSexceptionhierarchy.MostJCICSmethodsaredefinedasthrowingcheckedexceptions,andthesecheckedexceptionsrepresentthemajorityofconditionsthatanapplicationmaybeexpectedtohandle.

EacherrorconditionfromaCICScommandismappedtoanexception,andthisexceptionisasubclassoftheCICSconditionexception.

Asanexample,theCICScommandtoreadanelementfromatemporarystoragequeuemayreturnanITEMERRORconditiontoindicatethequeuedidnotcontaintheelementrequested.

IntheJCICSAPI,anelementisreadfromtheTSQusingthereaditemmethod.Thismethodsignaturedeclaresitmaythrow(amongstothers)anItemErrorException,whichistheJCICSAPIequivalentoftheITEMERRORcondition.

SeethequeryqueuemethodinthetemporarystorageresourcesampleclasstoseehowtheITEMERRORandQIDERRconditionsarehandledasexpectederrors,whileanyothererrorconditionresultsinafailureoftherequest,

ThereareonlyafewuncheckedexceptionsintheJCICSAPI,andtheyallextendtheCICSruntimeexceptionclass.

AlloftheseexceptionsrepresentconditionswithinCICSthatshouldnotbehandledbyanapplication.

JavacoderunninginCICSshouldnotcatchtheseexceptions,eitherexplicitlyinacatchblock,orimplicitlybycatchingasuperclassoftheseexceptions.Instead,theyshouldbeallowedtopropagateoutoftheJavaenvironmentandbacktoCICS,wheretheunitofworkcanberolledback.

Page 22: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

NoteincludedinthislististheAbendExceptionwhichrepresentsanabendofaCICStask,andshouldonlybecaughtifyouwishtodevelopyourownabendhandlingroutine.

ItimportanttostressthathavingatryblockthatcatchesanysuperclassofthejavadotlangdotexceptionclassshouldnotbeusedwheninvokingtheJCICSAPI.

ItimportanttostressthathavingatryblockthatcatchesanysuperclassofthejavadotlangdotexceptionclassshouldnotbeusedwheninvokingtheJCICSAPI.

<<Notetovideoteam.Youwillprobablyneedtopausethespeakerhereforashortwhile–thecomplexityofthisslidewasn’treallythoughtaboutwhenpreparingthescript.ThankfullyIamoff-screen.>>

TheJavaErrorclassrepresentsafatalerrorconditionintheJVMthatshouldnotbecaughtbyanapplication.

ThesameappliestotheCICSerrorclass,whichextendsjavadotlangdoterror.AnapplicationshouldnotattempttohandleafatalCICSerror,butinsteadallowtheexceptiontopropagatebacktotheCICSenvironmenttoallowfullrecoverytotakeplace.

IfaJavaexceptionsuchasanullpointerexceptionisallowedtopropagateoutoftheJavacodeandbacktotheJVMserverruntime,thisisgenerallysurfacedasoneoftheCICSabendsstartingwithAJ.

Mostcommonly,anuncaughtexceptionwillresultinanAJ04abend,andthecurrentunitofworkwillberolled-back.

ItisalsopossibleforaJavaapplicationtoissueanabenddirectly,usingoneoftheabendorforceabendmethodsintheTaskclass.ThisissimilarinconcepttothethrowingofJavaexception,asitcanallowsaCICSabendhandlertotakecontroloferrorprocessing.

Thevariousformsoftheabendmethodallowanapplicationtooptionallyspecifyanabendcodeorifadumpisrequired.

Theforceabendmethodsprovidethesameoptionsastheirequivalentabendmethods,butareequivalenttospecifyingtheCANCELkeywordontheEXECCICSABENDcommand.Invokingaforce

Page 23: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

abendmethodwillalwaysterminatethetaskabnormally,andoverridesanyexistingabendhandlersthathavebeenestablishedforthetask.

InoursampleVsamKsdsFileResourceclassweusethefollowingtrycatchblocktohandleCICSerrorconditionswhendeletingitemsfromaVSAMfile

TheRecordNotFoundExceptionisacheckedexceptionbutisanormalsituationontheinitialbrowse,assocanbeignoredwhenbrowsingthefile.

AllotherCICSconditionexceptionareunexpected,andinthissituationwethrowtheJAX-RSInternalServerErrorExceptionwhichwillcauseaHTTPservererrortobereturnedtothecaller.

ThislecturehasintroducedtheconceptofcheckedanduncheckedexceptionsinJava,alongwiththethrowingandcatchingmechanismusedtopropagatetheexceptionobjects.

WehaveseenhowtheJCICSAPImapsCICSerrorconditionvaluestoexceptions,andhowCICSabendsareprocessed.

RememberitisacceptableforanapplicationtocatchandhandleCICSconditionexceptions,butitstronglyrecommendedthatCICSruntimeexceptionsareallowedtopropagatebacktotheCICSenvironment.

Finally,welookedathowJavaexceptionsaremappedtoabendsinCICSprograms,alongwiththeAPIsrequiredtoissueabendsdirectlyfromJavacode.

Thankyouforwatching.

Section6Lecture1

Inthiscourse,wehaveextendedourknowledgeofJavadevelopmentinCICS.

WecoveredsomeofthefundamentalconceptsyouneedtounderstandasaJavadeveloperwheninteractingwithCICS,andthenusedthesefundamentalstoinvokeCICSprogramsfromtheLibertyenvironment.

Page 24: Extending a CICS Web application using JCICS · • Fundamentals of using the JCICS API ... In the “Developing a RESTful Web application for Liberty in CICS” course, we looked

WethenlookedattheuseoftheJCICSAPItoaccessCICSresourcesincludingVSAMfilesandTSQs,andexaminedhowJavaapplicationscanparticipateinCICSunitofworksupport.

Finally,welookedattheconceptsandpracticalitiesofhandlingerrorconditionsusingJava.

Manycodesamples,includingtheonesusedinthiscourse,areavailableonourCICSDevgithubsite.

ThisconcludesourcoursearoundextendingaCICSwebapplicationusingJCICS.

Thank-youforwatching.