SAP--ABAP351Advanced and Generic Programming in AB

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

ABAP351AdvancedandGenericProgramminginABAPGerdKluger,SAPAGBjörnMielenhausen,SAPAG©SAPAG2004,SAPTechEd/ABAP351/3ObjectivesAftercompletingthisworkshopyouwillbeableto:„Understandhowtomakeyourprogramsmoreflexible„Writegenericservicesthatcanworkwitharbitrarilystructureddata„Distinguishdifferentkindsofgenericity„UsegenerictypestoaddflexibilityandsafetytoABAPprograms„ExplaintheABAPtypesystemandtheRTTS„CreateABAPtypesatruntime©SAPAG2004,SAPTechEd/ABAP351/4SessionOverviewSimpleGenericConceptsinABAPDynamicTokenSpecificationFullyGenericProgramsRTTS&DynamicTypeCreation©SAPAG2004,SAPTechEd/ABAP351/5FieldSymbolsDATA:text(20)TYPEcVALUE'Helloworld'.FIELD-SYMBOLS:fsTYPEany.ASSIGNtextTOfs.WRITE/fs.FieldsymbolsarealiasesrepresentingfieldsdynamicallyAssignmentoffieldstofieldsymbolsatruntimeNocopyingFieldsymbolsarenotpointers©SAPAG2004,SAPTechEd/ABAP351/6CastingFieldSymbolsTYPES:MY_TYPE(9)TYPEC.DATA:SmallField(5)TYPEC,LargeField(10)TYPECVALUE'1234567890',TypeName(7)TYPECVALUE'MY_TYPE',SomeTypeTYPEREFTOcl_abap_typedescr.FIELD-SYMBOLS:faTYPEANY,fsTYPEmy_type.ASSIGNLargeFieldTOfsCASTING.ASSIGNLargeFieldTOfaCASTINGTYPEMY_TYPE.ASSIGNLargeFieldTOfaCASTINGTYPEN.ASSIGNLargeFieldTOfaCASTINGTYPE(TypeName).SomeType=cl_abap_typedescr=describe_by_name('MY_TYPE‘).ASSIGNLargeFieldTOfaCASTINGTYPEHANDLESomeType.ASSIGNLargeFieldTOfaCASTINGLIKESmallField.ASSIGNLargeFieldTOfaCASTINGLIKEfa.Castingto......staticallycompletelyspecifiedtype...generictype...dynamicfieldtype...staticfieldtype...dynamicallyspecifiedtype©SAPAG2004,SAPTechEd/ABAP351/7DataReferences(1)ReferencetypeREFTOtypenameforreferencestoarbitrarydataobjectsAdatareferencevariableissetby„CREATEDATAdrefTYPE|LIKE...„GETREFERENCEOFDataObjectINTOdrefAccesstodataobjectofreference„Referenceistyped?„X=dref-*.accessthecompletedataobject„Y=dref-comp.accesscomponentofastructure„Referenceisuntyped?(e.g.REFTODATA)„ASSIGNdref-*TOf.accesscompletedataobject...„ASSIGNCOMPONENT'comp'OFSTRUCTUREftofc....thenaccesscomponentifdataobjectisastructure©SAPAG2004,SAPTechEd/ABAP351/8DataReferences(2)References...„...aresomekindofSavePointers„...canbeusedascontainersforarbitrarydataobjects,e.g.tablesofdatareferences„...canbedefinedinthedatadictionary©SAPAG2004,SAPTechEd/ABAP351/9DynamicCreationofDataObjects(1)Dynamicinstantiationofdatatypesontheheap,forgenericprogrammingSyntaxCREATEDATAdrefTYPEtype|(typename).CREATEDATAdrefTYPETABLEOFtype|(typename).CREATEDATAdrefTYPEREFTOtype|(typename).CREATEDATAdrefTYPEHANDLEtypeobj.CREATEDATAdrefLIKEfield.©SAPAG2004,SAPTechEd/ABAP351/10DynamicCreationofDataObjects(2)TYPES:BEGINOFstruc,aTYPEi,bTYPEcLENGTH8,ENDOFSTRUC.DATA:drefTYPEREFTODATA,tnameTYPEstring,strTYPEstruc,intTYPEi.FIELD-SYMBOLS:intTYPEi,strTYPEstruc,fTYPEany.drefCREATEDATAdrefTYPEstruc.drefASSIGNdref-*TOstr.str36ABCstr-a=36.str-b='ABC'.drefCREATEDATAdrefLIKEint.ASSIGNdref-*TOint.int5int=5.dreftname='SFLIGHT'.CREATEDATAdrefTYPE(tname).ASSIGNdref-*TOf.fSELECTSINGLE*FROM(tname)INTOf.000AA0017©SAPAG2004,SAPTechEd/ABAP351/11GenericTypesFIELD-SYMBOLS:fs_anyTYPEANY,fs_cTYPEC.anylengthGenerictypespecificationofFieldSymbolsParameters(ofsubroutines)FORMFoo_1USINGp1TYPEANY....ENDFORM.FORMFoo_2USINGp1TYPEX....ENDFORM.©SAPAG2004,SAPTechEd/ABAP351/12ABAPTypeHierarchytypesdatatypesobjecttypeselementarydatatypesinterfacesclassescomplexdatatypesstructuretypestabletypesreferencetypesfixedlengthvariablelengthdatareferencetypesobjectreferencetypes©SAPAG2004,SAPTechEd/ABAP351/13GenericTypesSTANDARDTABLESORTEDTABLEINDEXTABLEHASHEDTABLEANYTABLEC,N,X,PCSEQUENCE,XSEQUENCE,CLIKEANY,DATASIMPLE,NUMERICFullygenericPartiallygenericGenericlengthGenerictablekindandkey©SAPAG2004,SAPTechEd/ABAP351/14Exercise:InternalTableListWriterWriteaformWRITE_TABLEwhichacceptsanyinternaltable.WritethecontentsoftheinternaltabletotheABAPlist,linebylineandfieldbyfield.DefineandfillaninternaltablewithalinetypeofyourchoicetotesttheformWRITE_TABLE.TIP:UseLOOPASSIGNINGnestedwithASSIGNCOMPONENTcompindexOFSTRUCTUREandDOlooptoaccesseachfieldofeveryline.TIP:IfyouneedmoreinformationaboutthesyntaxandthesemanticsofanABAPstatementuseOnline-HelpbypressingF1andenteringthefirstwordofthestatement.©SAPAG2004,SAPTechEd/ABAP351/15SessionOverviewSimpleGenericConceptsinABAPDynamicTokenSpecificationFullyGenericProgramsRTTS&DynamicTypeCreation©SAPAG2004,SAPTechEd/ABAP351/16DynamicTokenSpecificationABAPstatementsallowtospecifysomepartsdynamically.Generalsyntax:“(token)”wheretokenisafieldevaluatedatruntime.Rule:Thecontentsofthetokenmustbeinuppercase.Nostatictypechecksfordynamicstatements.Runtimeerrorsoccurifthecontentsofthetokenareinvalid.*StaticSORTstatementSORTitabBYcomp.*DynamicSORTstatementname='COMP'....SORTitabBY(name).©SAPAG2004,SAPTechEd/ABAP351/17DifferentTypesofDynamicTokenSpecificationThereare5typesofdynamictokenspecification„Dynamicfieldspecification:Thetokencontainsthenameofafield„Dynamictypespecification:Thetokencontainsatypename„Dynamiccomponentspecification:Thetokencontainsthenameofacomponentofastructure„

1 / 80
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功