91
COMP275 State-of-the-Art ABAP Modern Business Programming with ABAP Objects Horst Keller, SAP AG Ulrike Bossong, SAP AG Chris Swanepoel, SAP AG

COMP275 Print Version

  • Upload
    koizak

  • View
    36

  • Download
    1

Embed Size (px)

Citation preview

  • COMP275 State-of-the-Art ABAPModern Business Programming with ABAP ObjectsHorst Keller, SAP AGUlrike Bossong, SAP AGChris Swanepoel, SAP AG

  • Disclaimer

    This presentation outlines our general product direction and should not be relied on in making a purchase decision. This presentation is not subject to your license agreement or any other agreement with SAP. SAP has no obligation to pursue any course of business outlined in this presentation or to develop or release any functionality mentioned in this presentation. This presentation and SAP's strategy and possible future developments are subject to change and may be changed by SAP at any time for any reason without notice. This document is provided without a warranty of any kind, either express or implied, including but not limited to, the implied warranties of merchantability, fitness for a particular purpose, or non-infringement. SAP assumes no responsibility for errors or omissions in this document, except if such damages were caused by SAP intentionally or grossly negligent.

  • AgendaOverview Powerful ABAP ConceptsABAP ObjectsExercises OverviewExercise 1 Create a PackageExercise 2 Create a Static ClassExercise 3 Implement an InterfaceExercise 4 Create SubclassesExercise 5 - Polymorphic Call of Redefined MethodsExercise 6 Handle an Exception

  • OverviewSAP Business Application Programming 1/3

    Remote System(SAP, non-SAP)

    Tabular Data in Tables of a Central Relational DatabaseABAP and JavaApplication ProgramsPresentation LayerApplication LayerPersistence LayerNetWeaverApplication ServerSupport of various user interfaces(NetWeaver Business Client, Browser, SAP GUI)

  • OverviewSAP Business Application Programming 2/3

    Remote System(SAP, non-SAP)

    Tabular Data in Tables of a Central Relational DatabaseABAP and JavaApplication ProgramsPresentation LayerApplication LayerPersistence LayerNetWeaverApplication ServerSupport of various operating systems(such as Windows, Unix)

  • OverviewSAP Business Application Programming 3/3

    Remote System(SAP, non-SAP)

    Tabular Data in Tables of a Central Relational DatabaseABAP and JavaApplication ProgramsPresentation LayerApplication LayerPersistence LayerNetWeaverApplication ServerSupport of various databases(such as DB2, Max DB)

  • OverviewNetWeaver Application Server SAP NetWeaver Application Server offers

    Multi-layer architectureA reliable, proven runtime environment for ABAP (and Java) programsHigh scalabilityComfortable development environmentsThe highest security standards for executing complex business processes

    ABAPstackNetWeaverApplication ServerJavastackNW AS ABAPNW AS Java

  • OverviewNetWeaver Application Server ABAP

    NW AS ABAPBSPWeb DynproOpen SQLDynproNative SQLData Base InterfaceICFXSLT/STABAP/ABAP ObjectsCFWRFC InterfaceGatewayTaskhandlerEnqueueDispatcherSAP OSDatabaseOSICMADBC

  • OverviewFrom SAP Basis to SAP NW AS ABAPSAPBasisSAP Netweaver ASABAP/4 AllgemeinerBerichtsAufbereitungsProzessorABAP AdvancedBusinessApplicationProgrammingABAP Objectsin eSOA enterpriseService OrientedArchitectureState-of-the-ArtABAPWeb DynproABAP &

  • OverviewEnd-to-end SOA Infrastructure Process ComponentsSAP Business SuiteOrder Mgmt....Platform ServicesSAP NetWeaver ComponentsNon SAP & LegacyService & Event CompositionService & Event EnablementBusiness Process Composition & ManagementEnterprise SOAProvisioning Service- enabled Applications SOA Inter- operability Enterprise SOAConsumption User InterfaceFormsPortal DashboardsSAP GUIMobileBusiness ClientDuetUI CompositionService BusCustomer & Partner ApplicationsInformation CompositionSOA Design Governance Connectivity & IntegrationMDMBISOA ManagementBusiness PartnerWhere is ABAP?

  • OverviewHow to Provide Enterprise Services in ABAPService ImplementationRuntimeConsuming ApplicationsComposite ApplicationABAP Program3rd party applicationConsuming ApplicationsComposite ApplicationABAP Program3rd party applicationIntegration ServerNW AS ABAPGenerate and Implement ABAP ProxyConfigure and Publish ServiceServer-Side-Proxy Generation

  • OverviewServer Side Proxy Classes and ABAP Objects

    NW AS ABAP

    ClientsPersistenceServicesServer sideproxy classesApplication State-of-the-Art ABAP is service oriented programming with ABAP Objects!

  • OverviewService Oriented Application Programming

    NW AS ABAP

    ClientsUI ServicesPersistenceServicesServer sideproxy classesApplicationEnterprise-ready service oriented applicationsWeb DynproState-of-the-ArtABAP

  • Overview SOA with Powerful and Proven ABAP Concepts METHOD ... DATA itab TYPE dbtab. SELECT ... FROM dbtab INTO TABLE itab ... LOOP AT itab ... ... ENDLOOP. ... ENDMETHOD. State-of-the-Art ABAP means using powerful and proven ABAP concepts within ABAP Objects!

  • OverviewRules for State-of-the-Art ABAPSeparation of Concerns Make sure your applications are modelled as strictly service-oriented, always disentangle the logics for proxies (presentation, external connections, persistence) and application.Modern ABAP Keep your coding clean and up-to-date. Do not use language elements that are marked as obsolete (such as FORM ... ENDFORM). Apply new language constructs in your coding as they become available.KISS Keep It Simple, Stupid Keep the complexity of your code manageable (comment your code appropriately, restrict the number of executable statements per procedure, restrict the maximum nested block depth).Quality Test all aspects of your programs with the respective test tools.

  • AgendaOverview Powerful ABAP ConceptsABAP ObjectsExercises OverviewExercise 1 Create a PackageExercise 2 Create a Static ClassExercise 3 Implement an InterfaceExercise 4 Create SubclassesExercise 5 - Polymorphic Call of Redefined MethodsExercise 6 Handle an Exception

  • Powerful ABAP Concepts ABAP - More than a LanguageABAP A Powerful FrameworkFor Business ProgrammingIntegrated Database AccessTransaction Support on Server LevelBuffer for Database ObjectsFine Granular Locking Concept For Database TablesInternationalization SupportData Dictionary for Declarative Data ManagementEasy Management of Development Landscape Special Data Types for Business ProgrammingStrong Support for Dynamic ProgrammingPowerful IDE for Server-Side DevelopmentUI Development on Server

  • Powerful ABAP ConceptsExample Server Side Development

    Dev. Client 1

    Dev. Client 2

    Dev. Client 3Program 1active versionhas developedProgram 1new version, not yet activatedVisible in the whole systemIs currently developpingVisible only to Developer 1

  • Powerful ABAP Concepts Example Change and Transport System

    Development SystemNW AS ABAP 1Consolidation SystemNW AS ABAP 2Production SystemNW AS ABAP 3

  • Powerful ABAP Concepts Example UI DevelopmentDevelopment of UI Service Level on Application Server Easy Re-use of Dictionary TypesIntegrated Field and Value Help (F1, F4)Integrated support for InternationalizationIntegrated into life-cycle management

    Classical Dynpro Web Dynpro ABAP

    Exercise prepared!

  • SAPLUWDatabaseaccessesDBLUWDBLUWDBLUWPowerful ABAP Concepts Example - Transaction ManagementWeb Dynpro ApplicationWeb Dynpro View BWeb Dynpro View AWeb Dynpro View CXXX xxxx xxxx xxx xxx xx UUU uuuu uuuu uuu uuu uu SAP LockingPrepared forExercise!

  • Powerful ABAP ConceptsExample - Type Declarations and TypingABAP Dictionary FIELD ... DBTABDatabase TablesWeb Dynpro____TYPES local_type TYPE HASHED TABLE OF dbtab WITH UNIQUE KEY ...

    DATAscreen_fieldTYPE field. DATAdbtab_waTYPE dbtab.

    DATAdbtab_tabTYPE local_type. METHODS meth IMPORTING para1 TYPE field EXPORTING para2 TYPE local_type.

  • Powerful ABAP Concepts Example - Built-in Database AccessDML Platform IndependentOpen SQLNative SQLADBCDATA: sql TYPE REF TO cl_sql_statement, stmt TYPE string.

    stmt = `SELECT ... `. sql->execute_query( stmt ).EXEC SQL.

    SELECT...

    CREATE TABLE ...

    EXECUTE PROCEDURE ... ENDEXEC.SELECT... FROM... INTO... WHERE... GROUP BY... HAVING... ORDER BY...

    INSERT... UPDATE... MODIFY... DELETE...DCL: Locking etc. is managed by transaction concept DML and DDL Platform Dependent

  • Powerful ABAP Concepts Example - Handling Tables Database TablesTables on Screens____

  • Powerful ABAP ConceptsExample Internal TablesDATAvehicle_tabTYPETABLEOF REFTOcl_abap_intro_vehicle. DOnTIMES. CREATEOBJECTvehicle. APPENDvehicleTOvehicle_tab. ENDDO. LOOPATvehicle_tabINTOvehicle. vehicle->show_speed(). ENDLOOP.Three kinds of internal tables:Standard tables Sorted tablesHashed tables

  • Powerful ABAP Concepts Example - Built-in XML SupportCALLTRANSFORMATIONsimple_trans SOURCEcarriers=carrier_tab RESULTXMLxml_xstring.

    Carriers: Id Name Homepage Transformation (ST or XSLT)

  • Powerful ABAP Concepts Example - Language EnvironmentText pool with language dependent text elements Text environment with language dependent Locale and System Code PageFormat settings with country specific number, date, and time formats Automatic Support for Internationalizationoutput = text-sym.Text Symbol,as an Example forText Elements

  • Powerful ABAP ConceptsProof of ConceptABAP is the language in which most of the business applications of the worlds largest ERP vendor are developed.

  • AgendaOverview Powerful ABAP ConceptsABAP ObjectsExercises OverviewExercise 1 Create a PackageExercise 2 Create a Static ClassExercise 3 Implement an InterfaceExercise 4 Create SubclassesExercise 5 - Polymorphic Call of Redefined MethodsExercise 6 Handle an Exception

  • ABAP Objects What are ABAP Objects?TechEds 2000 - 2005

  • ABAP Objects Why use ABAP ObjectsTechEd 2003EncapsulationInstantiationInheritanceInterfacesPolymorphismExceptionsEventsExplicitnessSimplicityCleaner SyntaxCleaner Semantics

  • ABAP Objects State-of-the-Art ABAP ProgrammingYou use ABAP Objects because state-of-the-art technologies understand ABAP Objects!

  • ABAP ObjectsHands-On!

    Web Dynpro ProxiesPersistence ProxiesYour Classes!

  • AgendaOverview Powerful ABAP ConceptsABAP ObjectsExercises OverviewExercise 1 Create a PackageExercise 2 Create a Static ClassExercise 3 Implement an InterfaceExercise 4 Create SubclassesExercise 5 - Polymorphic Call of Redefined MethodsExercise 6 Handle an Exception

  • Exercises OverviewCar Rental ApplicationImplementation of the reservation of a car by a selected customerThree layers are involvedPresentation layerApplication layer Persistence layerThe presentation layer is provided as an Web Dynpro Application using a prepared car rental interface.Exemplary implementation of one class of the persistence layerImplementation of the application layer by implementing the car rental interface

    Presentation LayerApplication LayerPersistence Layer

  • Exercise Overview Persistence LayerThree database tables are prepared for the persistence layerZCR_CUSTOMERSZCR_CARSZCR_RESERVATIONS Three classes for handling data base access are prepared as static classesZCL_CR_CUSTOMERS_MANAGERZCL_CR_CARS_MANAGERZCL_CR_RESERVATIONS_MANAGERThe class ZCL_CR_CARS_MANAGER will be implemented in the exercise NAMEIDCLIENTZCR_RESERVATIONSZCR_CARSZCR_CUSTOMERS

    CLIENTLICENSE_PLATECATEGORY

    CLIENTRESERVATION_IDCUSTOMER_IDLICENSE_PLATEDATE_FROMDATE_TO

  • Exercise Overview Persistence and Application LayerZIF_CR_CAR_RENTAL_SERVICEZCL_CR_RESERVATION_SERVICEZCL_CR_CUSTOMERS_MANAGERZCL_CR_RESERVATIONS_MANAGERApplication LayerPersistence LayerProvidedPrepared

  • Exercise Overview Persistence and Application LayerZIF_CR_CAR_RENTAL_SERVICEZCL_CR_RESERVATION_SERVICEZCL_CR_CARS_MANAGERZCL_CR_CUSTOMERS_MANAGERZCL_CR_RESERVATIONS_MANAGERApplication LayerPersistence LayerTo Be ImplementedProvidedExercise 2

  • Exercise Overview Persistence and Application LayerZIF_CR_CAR_RENTAL_SERVICEZCL_CR_CAR_RENTAL_SERVICEZCL_CR_RESERVATION_SERVICEZCL_CR_CARS_MANAGERZCL_CR_CUSTOMERS_MANAGERZCL_CR_RESERVATIONS_MANAGER

    Application LayerPersistence LayerTo Be ImplementedProvidedExercise 3

  • Exercise Overview Persistence and Application LayerZIF_CR_CAR_RENTAL_SERVICEZCL_CR_CAR_RENTAL_SERVICEZCL_CR_RESERVATION_SERVICEZCL_CR_CARS_MANAGERZCL_CR_CUSTOMERS_MANAGERZCL_CR_RESERVATIONS_MANAGER

    Application LayerPersistence LayerTo Be ImplementedProvidedAbstract!

  • Exercise Overview Persistence and Application LayerZIF_CR_CAR_RENTAL_SERVICEZCL_CR_CAR_RENTAL_SERVICEZCL_CR_RESERVATION_SERVICEZCL_CR_RESERVATION_CATBZCL_CR_RESERVATION_CATAZCL_CR_RESERVATION_CATCZCL_CR_CARS_MANAGERZCL_CR_CUSTOMERS_MANAGERZCL_CR_RESERVATIONS_MANAGER

    Application LayerPersistence LayerTo Be ImplementedProvidedExercise 4

  • Exercise Overview Persistence and Application LayerZIF_CR_CAR_RENTAL_SERVICEZCL_CR_CAR_RENTAL_SERVICEZCL_CR_RESERVATION_SERVICEZCL_CR_RESERVATION_CATBZCL_CR_RESERVATION_CATAZCL_CR_RESERVATION_CATCZCL_CR_CARS_MANAGERZCL_CR_CUSTOMERS_MANAGERZCL_CR_RESERVATIONS_MANAGER

    Application LayerPersistence LayerTo Be ImplementedProvidedExercise 5

  • DEMO

  • AgendaOverview Powerful ABAP ConceptsABAP ObjectsExercises OverviewExercise 1 Create a PackageExercise 2 Create a Static ClassExercise 3 Implement an InterfaceExercise 4 Create SubclassesExercise 5 - Polymorphic Call of Redefined MethodsExercise 6 Handle an Exception

  • Exercise 1PackagesZC_CR_PACKAGE_TOPZC_CR_PACKAGEZC_CR_PACKAGE_XXZC_CR_PACKAGE_YYZC_CR_PACKAGE_01ZC_CR_PACKAGE_02ZC_CR_PACKAGE_...The provided superpackage ZC_CR_PACKAGE_TOP contains three prepared subpackages: Package ZC_CR_PACKAGE contains prepared objectsPackage ZC_CR_PACKAGE_XX contains sample solutions for exercises 1 to 5Package ZC_CR_PACKAGE_XX contains a sample solution for exercise 6 The other subpackages ZC_CR_PACKAGE_01, will be created in the exercise.

  • DEMO

  • AgendaOverview Powerful ABAP ConceptsABAP ObjectsExercises OverviewExercise 1 Create a PackageExercise 2 Create a Static ClassExercise 3 Implement an InterfaceExercise 4 Create SubclassesExercise 5 - Polymorphic Call of Redefined MethodsExercise 6 Handle an Exception

  • Exercise 2Defining own ClassesCLASSzcl_cr_cars_manager_xx DEFINITION PUBLIC FINAL OPEN FOR PACKAGE CREATEPACKAGE. PUBLICSECTION. ... PROTECTEDSECTION. ... PACKAGESECTION. CLASS-METHODSget_cars_by_category IMPORTING i_categoryTYPEzcr_category RETURNING value(r_cars)TYPEzcr_cars_tt. PRIVATESECTION. ... ENDCLASS. Global classes are defined with the Class Builder in the ABAP Workbench. Global classes are visible to any other repository object and usable according to the package concept.Besides global classes in class pools, local classes can be defined in almost all kinds of ABAP programs

  • Exercise 2Defining own Classes Global ClassesAll components are represented as screen elements in the Form-based Class Builder!The Class Builder generates ABAP coding from your input.

  • Exercise 2Defining own Classes Class Builder ModesAs of Release 7.1 you can switch to a Source Code-Based mode of the Class Builder!

  • Exercise 2Method Implementation in Form-based Mode

  • Exercise 2 Defining own Classes Attributes 1/2CLASSzcl_cr_testclassDEFINITION PUBLIC FINAL OPEN FOR PACKAGE CREATEPACKAGE. PUBLIC SECTION. PROTECTED SECTION. PACKAGE SECTION. PRIVATESECTION. DATAattrTYPEstring. CLASS-DATAstatic_attrTYPEstring. ENDCLASS.Instance Attribute

  • Exercise 2 Defining own Classes Attributes 2/2CLASSzcl_cr_testclassDEFINITION PUBLIC FINAL OPEN FOR PACKAGE CREATEPACKAGE. PUBLIC SECTION. PROTECTED SECTION. PACKAGE SECTION. PRIVATESECTION. DATAattrTYPEstring. CLASS-DATAstatic_attrTYPEstring. ENDCLASS.

  • Exercise 2 Defining own Classes Encapsulation 1CLASSzcl_cr_testclassDEFINITION PUBLICFINAL OPEN FOR PACKAGECREATEPACKAGE. PUBLIC SECTION. PROTECTED SECTION. PACKAGE SECTION. PRIVATESECTION. DATAattrTYPEstring. CLASS-DATAstatic_attrTYPEstring. ENDCLASS.Each component of a class is declared in one of four possible visibility sections defining Public Protected Package PrivatevisibilityPackage visiblity is available as of Release 7.1

  • Exercise 2 Defining own Classes Encapsulation 2Without OPEN FOR PACKAGE With OPEN FOR PACKAGE (as of Release 7.1)

    Visible forPUBLIC SECTIONPROTECTED SECTIONPRIVATE SECTIONSame Class and FriendsXXXAll SubclassesXX-All Repository ObjectsX--

    Visible forPUBLIC SECTIONPROTECTED SECTIONPACKAGE SECTIONPRIVATE SECTIONSame Class and FriendsXXXXRepository Objekts of same PackageXXX-All SubclassesXX--All Repository ObjectsX---

  • Exercise 2 ABAP Objects Summary of Class Components

    CLASSDEFINITION ... ...SECTION. TYPES ... CONSTANTS ... CLASS-DATA ... DATA ... CLASS-METHODS ... METHODS ... CLASS-EVENTS ... EVENTS ... ENDCLASS.

    Class DefinitionVisibility SectionsType DeclarationsStatic AttributesInstance AttributesStatic and Instance MethodsStatic and Instance Events

  • Exercise 2 Static Class Contains only static attributes and methods No need to create an instance of the class

    Recommendation when to use static classes:In cases where only procedural aspects of methods play a role and object instantiation would unnecessarily complicate a program

  • Exercise 2Static Class of Persistence LayerZIF_CR_CAR_RENTAL_SERVICEZCL_CR_RESERVATION_SERVICEZCL_CR_CARS_MANAGERZCL_CR_CUSTOMERS_MANAGERZCL_CR_RESERVATIONS_MANAGERApplication LayerPersistence LayerTo Be ImplementedProvided

  • DEMO

  • AgendaOverview Powerful ABAP ConceptsABAP ObjectsExercises OverviewExercise 1 Create a PackageExercise 2 Create a Static ClassExercise 3 Implement an InterfaceExercise 4 Create SubclassesExercise 5 - Polymorphic Call of Redefined MethodsExercise 6 Handle an Exception

  • Exercise 3Interfaces - OverviewINTERFACE if1. METHODS: m1 ... ... ENDINTERFACE.INTERFACE if2. METHODS: m2 ... ... ENDINTERFACE.

  • Exercise 3 Implementing InterfacesBy implementing an interface in the public section of a class, the components of the interface are added to the components of the public section of the class. A component comp of an interface intf, is addressed by intf~comp within the class. The class must implement all non-abstract methods of the interface in its implementation part:

    CLASSzcl_cr_car_rental_serviceDEFINITION PUBLIC FINAL OPEN FOR PACKAGE CREATEPACKAGE. PUBLICSECTION. INTERFACESzif_cr_car_rental_service.

    METHODzif_cr_car_rental_service~make_reservation. ...ENDMETHOD.

  • Exercise 3Benefits of InterfacesBenefits of interfaces:Decoupling from implementationCan be defined by clientPolymorphismSeparation of different functionality

  • Exercise 3Implementing Interfaces in Global ClassesIn Form-Based mode, the Class Builder allows you to handle interface components like components of the class

  • Exercise 3Instanciating and Referencing Objects DATA: oref1 TYPE REF TO class, oref2 TYPE REF TO interface.

    Declaring reference variables Creating objects CREATE OBJECT: oref1 TYPE class, oref2 TYPE class. Accessing attributes and methods (static / instance) x = me->attr + oref1->attr + class=>attr.oref1->method1( ... ).oref2->method2( ... ).class=>method3( ... ).y = oref2->method4( ... ).

    Class Reference VariableInterface Reference VariableClass of Object-> Object Component Selector=> Class Component Selectororef

  • Exercise 3 Singleton PatternA singleton is a simple object-oriented pattern. Exactly one object can be instantiated from a singleton class.Benefit vs. static classes:You control when instantiation takes placeYou control the lifetime of the object. Using singletons is a little bit more complex than simply using static classesRecommended if control of object instantiation is important, e.g. to enable Garbage Collection

    CLASS DEFINITION CREATE PRIVATE

    METHODCLASS_CONSTRUCTOR. CREATEobjectsingle_ref. ENDMETHOD. METHODGET_SINGLE. r_single = single_ref. ENDMETHOD. GET_SINGLEoref

  • Exercise 3Singleton and Interface ImplementationZIF_CR_CAR_RENTAL_SERVICEZCL_CR_CAR_RENTAL_SERVICEZCL_CR_RESERVATION_SERVICEZCL_CR_CARS_MANAGERZCL_CR_CUSTOMERS_MANAGERZCL_CR_RESERVATIONS_MANAGER

    Application LayerPersistence LayerTo Be ImplementedProvided

  • DEMO

  • AgendaOverview Powerful ABAP ConceptsABAP ObjectsExercises OverviewExercise 1 Create a PackageExercise 2 Create a Static ClassExercise 3 Implement an InterfaceExercise 4 Create SubclassesExercise 5 - Polymorphic Call of Redefined MethodsExercise 6 Handle an Exception

  • Exercise 4Inheritance - OverviewobjectCLASS c1 DEFINITION [INHERITING FROM object].CLASS c2 DEFINITION [INHERITING FROM object].CLASS c11 DEFINITION INHERITING FROM c1.CLASS c12 DEFINITION INHERITING FROM c1.

  • Exercise 4Inheritance - RealizationCLASSzcl_cr_reservation_cata_xxDEFINITION PUBLIC INHERITINGFROMzcl_cr_reservation_service FINAL OPEN FOR PACKAGE CREATEPACKAGE. ENDCLASS.Defining a Subclass The present class becomes a subclass of an already existing superclass.You can only specify one superclass.Subclasses contain the components of all preceding superclasses.You can add new components in each subclass or redefine existing methods.Reference variables that have the type of a superclass can point to subclass objects.The root node of all classes is the predefined abstract class object.

  • Exercise 4Inheritance - Method RedefinitionMETHODcompute_price. r_price=super->compute_price( )*me->cata_rate. ENDMETHOD. ZCL_CR_RESERVATION_CATA_XXZCL_CR_RESERVATION_CATB_XXZCL_CR_RESERVATION_CATC_XXZCL_CR_RESERVATION_SERVICEMETHODcompute_price. r_price=me->basis_rate *(i_date_to-i_date_from+1). ENDMETHOD. METHODcompute_price. r_price=super->compute_price( )*me->catb_rate. ENDMETHOD. METHODcompute_price. r_price=super->compute_price( )*me->catc_rate. ENDMETHOD.

  • Exercise 4 Redefinition Abstract Superclass

    CLASSzcl_cr_reservation_serviceDEFINITION PUBLICABSTRACT CREATEPROTECTED. PROTECTEDSECTION. CONSTANTSbasis_rateTYPEzma_basis_rateVALUE20. DATAcar_tabTYPEzma_cars_tt. ... METHODScompute_price IMPORTING i_date_fromTYPEzcr_date_from i_date_toTYPEzcr_date_to RETURNING value(r_price)TYPEzcr_price. ENDCLASS.CLASSzcl_cr_reservation_serviceIMPLEMENTATION. METHOD compute_price . r_price=me->basis_rate*(i_date_to-i_date_from+1). ENDMETHOD. ENDCLASS.Component sharing with subclasses General method implementationGeneral abstract superclass

  • Exercise 4Redefinition Concrete Subclass

    CLASSzcl_cr_reservation_cata_xxDEFINITION PUBLIC INHERITINGFROMzcl_cr_reservation_serviceFINAL OPEN FOR PACKAGE CREATEPACKAGE. PROTECTEDSECTION. ... METHODScompute_priceREDEFINITION. PRIVATESECTION. CONSTANTScata_rateTYPEzcr_cat_scaleVALUE... ENDCLASS.CLASS zcl_cr_reservation_cata_01 IMPLEMENTATION. METHOD compute_price. r_price = super->compute_price( i_date_from = i_date_from i_date_to = i_date_to ) * me->cata_rate. ENDMETHOD. ENDCLASS.

    Method redefinition Special method implementationConcrete subclassCall of general implementation

  • Exercise 4Method Redefinition in SubclassesZIF_CR_CAR_RENTAL_SERVICEZCL_CR_CAR_RENTAL_SERVICEZCL_CR_RESERVATION_SERVICEZCL_CR_RESERVATION_CATBZCL_CR_RESERVATION_CATAZCL_CR_RESERVATION_CATCZCL_CR_CARS_MANAGERZCL_CR_CUSTOMERS_MANAGERZCL_CR_RESERVATIONS_MANAGER

    Application LayerPersistence LayerTo Be ImplementedProvided

  • DEMO

  • AgendaOverview Powerful ABAP ConceptsABAP ObjectsExercises OverviewExercise 1 Create a PackageExercise 2 Create a Static ClassExercise 3 Implement an InterfaceExercise 4 Create SubclassesExercise 5 - Polymorphic Call of Redefined MethodsExercise 6 Handle an Exception

  • Exercise 5 Polymorphism - OverviewDATA: iref TYPE REF TO interface, cref TYPE REF TO superclass.... iref->meth( ... ). cref->meth( ... ).irefAccessing methods in different objects with different behavior via the same interface. Polymorphism becomes available through inheritance and interfacesYou access objects via reference variablesYou can use one and the same reference variable (interface reference variable or superclass reference variable) to access objects of different classes with different implementationscref ??methmethThe static type of a reference variable can be more general than or equal to the dynamic type!

  • Exercise 5Polymorphism through Method Redefinition

    CLASS ZCL_CR_CAR_RENTAL_SERVICE_XX IMPLEMENTATION. ... METHOD zif_cr_car_rental_service~make_reservation.

    DATA reservation TYPE REF TO zcl_cr_reservation_service.

    ...

    CREATE OBJECT reservation TYPE

    reservation->make_reservation( ... ).

    ENDMETHOD. ...ENDCLASS. r_price = me->cata_rate * super->compute_price( ... ). me->compute_price( ... ).SuperclassSubclassesSuperclassReferenceSubclassImplementationmake_reservation

  • Exercise 5Persistence and Application LayerZIF_CR_CAR_RENTAL_SERVICEZCL_CR_CAR_RENTAL_SERVICEZCL_CR_RESERVATION_SERVICEZCL_CR_RESERVATION_CATBZCL_CR_RESERVATION_CATAZCL_CR_RESERVATION_CATCZCL_CR_CARS_MANAGERZCL_CR_CUSTOMERS_MANAGERZCL_CR_RESERVATIONS_MANAGER

    Application LayerPersistence LayerTo Be ImplementedProvided

  • DEMO

  • AgendaOverview Powerful ABAP ConceptsABAP ObjectsExercises OverviewExercise 1 Create a PackageExercise 2 Create a Static ClassExercise 3 Implement an InterfaceExercise 4 Create SubclassesExercise 5 - Polymorphic Call of Redefined MethodsExercise 6 Handle an Exception

  • Exercise 6Exception HandlingCX_ROOTCX_NO_CHECKCX_STATIC_CHECKCX_DYNAMIC_CHECKCLASS cx_... DEFINITION INHERITING FROM cx_..._check. ...ENDCLASS.DATA oref TYPE cx_...

    TRY. method( ... ). CATCH cx_... cx_... INTO oref. ... CLEANUP. ... ENDTRY. METHODS method RAISING cx_...

    METHOD method.

    RAISE cx_...

    ENDMETHOD.

  • Exercise 6Prepared Exceptions in the Car Rental ExerciseCX_STATIC_CHECKCX_CR_CAR_RENTALCX_CR_CARCX_CR_CUSTOMERCX_CR_NO_CUSTOMERCX_CR_NO_CAR_AVAILABLECX_CR_RESERVATIONCX_CR_LOCK

  • Exercise 6ABAP Runtime Exceptions

    CLASS ZCL_CR_CAR_RENTAL_SERVICE_XX IMPLEMENTATION. ... METHOD zif_cr_car_rental_service~make_reservation.

    DATA reservation TYPE REF TO zcl_cr_reservation_service.

    ...

    CREATE OBJECT reservation TYPE (name).

    reservation->make_reservation( ... ).

    ENDMETHOD. ...ENDCLASS.Runtime Error if name is wrong!

  • Exercise 6Handling Runtime Exceptions

    CLASS ZCL_CR_CAR_RENTAL_SERVICE_YY IMPLEMENTATION. ... METHOD zif_cr_car_rental_service~make_reservation.

    ...

    TRY. CREATE OBJECT reservation TYPE (name). CATCH ... RAISE EXCEPTION TYPE zcx_cr_reservation ... ... ENDTRY.

    ENDMETHOD. ...ENDCLASS.Here: Mapping to prepared exception

  • DEMO

  • Thank you!

  • Fuel your Career with SAP CertificationTake advantage of the enhanced, expanded and multi tier certifications from SAP today!What the industry is saying Teams with certified architects and developers deliver projects on specification, on time, and on budget more often than other teams.2008 IDC Certification Analysis

    82% of hiring managers use certification as a hiring criteria.2008 SAP Client Survey

    SAP Certified Application Professional status is proof of quality, and thats what matters most to customers.*Conny Dahlgren, SAP Certified Professional

  • FeedbackPlease complete your session evaluation.Be courteous deposit your trash, and do not take the handouts for the following session. Thank You !

  • Further Information

  • Building Your Business with SDN SubscriptionsSDN Subscriptions offers developers and consultants like you, an annual license to the complete SAP NetWeaver platform software, related services, and educational content, to keep you at the top of your profession. SDN Software Subscriptions: (currently available in U.S. and Germany) A one year low cost, development, test, and commercialization license to the complete SAP NetWeaver software platform Automatic notification for patches and updatesContinuous learning presentations and demos to build expertise in each of the SAP NetWeaver platform componentsA personal SAP namespace SAP NetWeaver Content Subscription: (available globally) An online library of continuous learning content to help build skills. To learn more or to get your own SDN Subscription, visit us at the Community Clubhouse or at www.sdn.sap.com/irj/sdn/subscriptions

  • Copyright 2008 SAP AGAll Rights ReservedNo part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice.Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.SAP, R/3, xApps, xApp, SAP NetWeaver, Duet, SAP Business ByDesign, ByDesign, PartnerEdge and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned and associated logos displayed are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary.The information in this document is proprietary to SAP. No part of this document may be reproduced, copied, or transmitted in any form or for any purpose without the express prior written permission of SAP AG. This document is a preliminary version and not subject to your license agreement or any other agreement with SAP. This document contains only intended strategies, developments, and functionalities of the SAP product and is not intended to be binding upon SAP to any particular course of business, product strategy, and/or development. Please note that this document is subject to change and may be changed by SAP at any time without notice. SAP assumes no responsibility for errors or omissions in this document. SAP does not warrant the accuracy or completeness of the information, text, graphics, links, or other items contained within this material. This document is provided without a warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability, fitness for a particular purpose, or non-infringement.SAP shall have no liability for damages of any kind including without limitation direct, special, indirect, or consequential damages that may result from the use of these materials. This limitation shall not apply in cases of intent or gross negligence.The statutory liability for personal injury and defective products is not affected. SAP has no control over the information that you may access through the use of hot links contained in these materials and does not endorse your use of third-party Web pages nor provide any warranty whatsoever relating to third-party Web pages.

    Weitergabe und Vervielfltigung dieser Publikation oder von Teilen daraus sind, zu welchem Zweck und in welcher Form auch immer, ohne die ausdrckliche schriftliche Genehmigung durch SAP AG nicht gestattet. In dieser Publikation enthaltene Informationen knnen ohne vorherige Ankndigung gendert werden.Einige von der SAP AG und deren Vertriebspartnern vertriebene Softwareprodukte knnen Softwarekomponenten umfassen, die Eigentum anderer Softwarehersteller sind.SAP, R/3, xApps, xApp, SAP NetWeaver, Duet, SAP Business ByDesign, ByDesign, PartnerEdge und andere in diesem Dokument erwhnte SAP-Produkte und Services sowie die dazugehrigen Logos sind Marken oder eingetragene Marken der SAP AG in Deutschland und in mehreren anderen Lndern weltweit. Alle anderen in diesem Dokument erwhnten Namen von Produkten und Services sowie die damit verbundenen Firmenlogos sind Marken der jeweiligen Unternehmen. Die Angaben im Text sind unverbindlich und dienen lediglich zu Informationszwecken. Produkte knnen lnderspezifische Unterschiede aufweisen.Die in dieser Publikation enthaltene Information ist Eigentum der SAP. Weitergabe und Vervielfltigung dieser Publikation oder von Teilen daraus sind, zu welchem Zweck und in welcher Form auch immer, nur mit ausdrcklicher schriftlicher Genehmigung durch SAP AG gestattet. Bei dieser Publikation handelt es sich um eine vorlufige Version, die nicht Ihrem gltigen Lizenzvertrag oder anderen Vereinbarungen mit SAP unterliegt. Diese Publikation enthlt nur vorgesehene Strategien, Entwicklungen und Funktionen des SAP-Produkts. SAP entsteht aus dieser Publikation keine Verpflichtung zu einer bestimmten Geschfts- oder Produktstrategie und/oder bestimmten Entwicklungen. Diese Publikation kann von SAP jederzeit ohne vorherige Ankndigung gendert werden.SAP bernimmt keine Haftung fr Fehler oder Auslassungen in dieser Publikation. Des Weiteren bernimmt SAP keine Garantie fr die Exaktheit oder Vollstndigkeit der Informationen, Texte, Grafiken, Links und sonstigen in dieser Publikation enthaltenen Elementen. Diese Publikation wird ohne jegliche Gewhr, weder ausdrcklich noch stillschweigend, bereitgestellt. Dies gilt u. a., aber nicht ausschlielich, hinsichtlich der Gewhrleistung der Marktgngigkeit und der Eignung fr einen bestimmten Zweck sowie fr die Gewhrleistung der Nichtverletzung geltenden Rechts. SAP haftet nicht fr entstandene Schden. Dies gilt u.a. und uneingeschrnkt fr konkrete, besondere und mittelbare Schden oder Folgeschden, die aus der Nutzung dieser Materialien entstehen knnen. Diese Einschrnkung gilt nicht bei Vorsatz oder grober Fahrlssigkeit.Die gesetzliche Haftung bei Personenschden oder Produkthaftung bleibt unberhrt. Die Informationen, auf die Sie mglicherweise ber die in diesem Material enthaltenen Hotlinks zugreifen, unterliegen nicht dem Einfluss von SAP, und SAP untersttzt nicht die Nutzung von Internetseiten Dritter durch Sie und gibt keinerlei Gewhrleistungen oder Zusagen ber Internetseiten Dritter ab. Alle Rechte vorbehalten.

    ***** The SAP NW Application Server ABAP consists of three layers: presentation, application, and database. The database layer of a system is made up of a central database with a database management system and the database itself. It not only contains the user data, but also the entire program code of the SAP NW AS and application programs, all administrative data, and Customizing settings.The application layer lies between the database layer and the presentation layer. It consists of one or more application servers (more than 100 servers possible) and a single message server, which is responsible for communication and load distribution within this layer. The programs that process the business logic of an application run in this layer. Technically, the actual processing takes place in work processes, which represent operating system processes. A fixed database connection is assigned to each work process. There is no fixed assignment of users to work processes. A lengthy user session can utilize different work processes sequentially.The kernel and the Basis services make up the part of the application layer that is specific to both the operating system and the database. They are responsible for user and process management, database access, communication with other systems, as well as system monitoring and administration. The software processes or virtual machines, that interpret the platform-independent byte code as operating system-specific machine language commands, run in the kernel. *****End-To-End SOA Infrastructure TodaySAP provides a comprehensive blueprint, that delivers key building blocks of the Enterprise Service Oriented Architecture (SOA). The Enterprise SOA blueprint shows how these building blocks facilitate innovation, enable business network transformation, and achieve operational excellence in an cost efficient way. Building blocks are organized in the following SOA principles which define ground rules for SOA capabilities:Enterprise SOA Consumption: Composition of service based applications by consuming business entities delivered through the platform.SOA Middleware: Communication and service management layer to ensure optimized interoperability between consumption, provisioning and external entities.And in both the consumption and the provisioning scenarios, the ESR has a key role to play. In the provisioning scenarios, ESR becomes the central place wher services are defined and where Design time Governance is enforced. In the consumption scenario, the rich semantics in the ESR help in doing effective Gap analysis and in discovering the right services. ***** After all is properly defined, you determine a backend system in which the server side proxy is generated.On the technical level in the Application Server ABAP this means: A global class is generated that provides the methods and parameters according to the way the service interface is defined in the ESR.

    In a next step you implement the business logic in the Class Builder.

    After the service is generated and implemented, you still have to configure it (WSADMIN and WSCONFIG in 7.00, SOAMANAGER in 7.10.)

    ***** There are more advantages to programming with ABAP than simply using a sophisticated programming language, and there are very good reasons for this. You require more than just the programming language to write business applications successfully. Efficient programming not only involves the writing of source code, especially in the case of very large projects. A single program with its code is only a building block in a component, which in turn is part of a solution. Furthermore, it is not just the creation of the solution that is relevant, but its entire lifecycle, especially considering that, on average, maintenance costs make up some 60% of software costs. When you write an ABAP program, it is, from the outset, integrated in an environment that supports its entire lifecycle. The ABAP Development Workbench, the programming environment of the SAP NW AS ABAP, supports the entire software development cycle with tools for: Programming in the ABAP language, Efficient debugging, Static and dynamic tests of different scales, Performance analyses, Organizing large projects, Updates and importing patches, Source code management, Connectors to Java and .NET world.

    ***** For those experienced with other programming languages like C, Java, or Visual Basic working with ABAP offers some features they might not be accustomed to. The structure of the development environment for ABAP is different from probably everything that you might have encountered so far: In ABAP, you program on the server from the outset. You do not develop the programs locally on your PC, nor do you store the sources in a versioning system or deploy the programs on the server at a later stage.In order to program with ABAP, you therefore require access to and developer authorization for the SAP NW Application Server ABAP. You write your programs using the ABAP Editor of the ABAP Workbench and the tools integrated there, which are also part of the server. However, the SAP NW Application Server ABAP not only contains the programming environment with its tools and utilities for supporting the software lifecycle. Developing with ABAP is closely connected to the server in another respect: Once you activate your source code, platform-independent byte code is generated, which the runtime environment interprets for the program execution. And this byte code generated from your ABAP program runs on the SAP NW AS ABAP. Usually many developers are working on the same server. This way, a problem known to all developers in large projects does not even arise: No quality manager needs to care about providing a system on which to deploy the programs from different developers and where to test the interaction of the programs from different developers in a project. Everything to accomplish this, is already done, and you as a developer already have your programs in the right place: As soon as your source code is activated the respective development object is visible on the central system. So the principle in ABAP is: Development on a central server. Once a development object is active it is visible in the whole system. Before only the owner of an object can work with this object.***** In ABAP all development objects are from the very outset integrated in a transport system. Each object belongs to a transport layer and a transport request. This way it is assured that the object not only has its proper place in a complex landscape from the beginning, but it is also guaranteed that the object is transported to the rights systems at the relevant point in time. In ABAP the assignment of development objects to transports is not something some Q-manager or other has to take care of, but a developer is forced by the tools to connect his objets to the transport system in the right way.When you create an object you have to provide a transport layer and a transport request for it: The transport layer is like a subway line and the transport request is like the tram. Assigning some object to a transport line is like buying a ticket for this line, while assigning an object to a transport request is like actually putting it on the train. Exporting the transport request is like the train leaving the station, and the import is the reverse. The typical landscape for ABAP development has at least three systems:While all development activities are located in the first system of this landscape, it is the consolidation system in which integration tests are run. Though all developers develop on the same system and changes are visible on the whole system as soon as they are activated, it is in the consolidation system where relevant development objects are transported to in a more final state and subsequently tested.If the tests show errors they are corrected in the development system, and at the end of the day if everything works out fine the results are transported to the productive system. If you are writing business programs, you are dependent on having certain program parts executed in full or not at all. If the program, for example, debits money on one account and credits money on another, it must not happen that the money is deducted from the one account and not credited on the other. If problems occur during this procedure, it must be ensured that these related postings are executed either in full or that none of them is executed.. This would mean that, in the latter case mentioned above, postings already executed would have to be reset entirely. Processes of this nature are generally called transactions. At the end of a transaction, it is confirmed and posted in its entirety to the database (COMMIT) or discarded in its entirety (ROLLBACK). One could assume that the SAP program can access the transaction handling process of the database. However, this is hardly possible. A business transaction may extend over several screens. It is not certain that a program works with the same work process over several screens. On the contrary, it is the feature of the SAP NW AS that it can work with much less work processes than users. If a program is just waiting for inputs, its work process so far can be passed to another user. A program can work with different work processes, one after the other, and a work process can be used by different programs, one after the other. Database transactions, however, cannot cover several work processes. If a work process changes its owner, the database transaction with which it was linked must be committed or rolled back. A typical ABAP application program can work with several different work processes, one after the other. Therefore, the SAP NW application server has its own transaction concept. The Open SQL statements INSERT, UPDATE, MODIFY, and DELETE allow you to program database changes that extend over several dialog steps. But even if you have not explicitly programmed a database commit, the implicit database commit that occurs after a screen has been processed concludes the database transaction. The solution to this problem is to combine all the update postings of a program using function modules. If you call a function module using the statement CALL FUNCTION ... IN UPDATE TASK, the function module is flagged for execution using a special update work process. The actual execution of the function module is postponed therefore. This means that you can write the Open SQL statements for the database changes in the function module instead of in your program, and call the function module at the point in the program where you would otherwise have included the statements. When you call a function module using the IN UPDATE TASK addition, it and its interface parameters are stored as a log entry in a special database table called VBLOG. You can then commit or roll back all the update postings of a program in one go. *****ABAP is the language in which SAP develops most of its application.The world market leader in business software relies on ABAP and still invests in this language.Most Applications of the recent edition of the Business Suite 7.0 are written in ABAP.The new interface of SAP ERP 6.0 is Web Dynpro ABAP.The ABAP installed base has millions of code lines the guarantee the efficient working of many of the worlds top 500 companies.

    Visibility of Components Public components can be addressed by all users, heirs and the class itself.Protected components can be addressed by heirs and the class itself.Private components can only be addressed by the class itself.

    Unlike trial versions which expire after 90 days, requiring you to uninstall, reinstall, and re-configure. SDN Subscriptions provides developers uninterrupted access to an environment that they can personalize and completely control, saving them valuable time and increasing productivity through reduced downtime.

    Specific subscriptions include: SAP NetWeaver Development Subscription. Hands-on access and ownership to the complete SAP NetWeaver software platform. (available in Germany and U.S.) Low cost, access to the SAP NetWeaver platform with a one year, development and commercialization license Choice of development method with SAP NetWeaver ABAP, Java, and/or composite applications Continuous learning presentations and demos to build skills in each of the SAP NetWeaver platform components SAP NetWeaver Content Subscription. An online library of continuous learning content to help build skills. (available globally)SAP NetWeaver Composition Subscription. Uninterrupted, total control for creating, testing, and selling Java-based solutions that integrate with SAP applications. (available in Germany and U.S.)

    To learn more or to get your own SDN Subscription, visit SAP NetWeaver, Development Subscription, www.sdn.sap.com/irj/sdn/devsubSAP NetWeaver, Content Subscription, www.sdn.sap.com/irj/sdn/subscriptions/contentSAP NetWeaver, Composition Subscription, www.sdn.sap.com/irj/sdn/subscriptions/composition

    Key Benefits include: Complete control Uninterrupted, hands-on access Latest NetWeaver software Continuous learning And Supporting services