ABAP objects and BSP - ELTE SAP Portal

36 downloads 548 Views 899KB Size Report
ABAP Objects and Business Server. Pages ... Object-oriented enhancement of ABAP. • Stepwise ..... Standard designs: design2003, design2002 and classic.
ABAP Course ABAP Objects and Business Server Pages

Lecturer: André Bögelsack, UCC Technische Universität München Author: Valentin Nicolescu, André Bögelsack ABAP Course

André Bögelsack, Valentin Nicolescu

1

Copyright 2008 UCC TU München All rights reserved 

Weitergabe und Vervielfältigung dieser Publikation oder von Teilen daraus sind, zu welchem Zweck und in welcher Form auch immer, ohne die ausdrückliche schriftliche Genehmigung durch HCC TU München nicht gestattet. In dieser Publikation enthaltene Informationen können ohne vorherige Ankündigung geändert werden.



Microsoft®, WINDOWS®, NT®, EXCEL®, Word®, PowerPoint® und SQL Server® sind eingetragene Marken der Microsoft Corporation.



IBM®, DB2®, OS/2®, DB2/6000®, Parallel Sysplex®, MVS/ESA®, RS/6000®, AIX®, S/390®, AS/400®, OS/390® und OS/400® sind eingetragene Marken der IBM Corporation.



ORACLE® ist eine eingetragene Marke der ORACLE Corporation.



INFORMIX®-OnLine for SAP und Informix® Dynamic ServerTM sind eingetragene Marken der Informix Software Incorporated.



UNIX®, X/Open®, OSF/1® und Motif® sind eingetragene Marken der Open Group.



Citrix®, das Citrix-Logo, ICA®, Program Neighborhood®, MetaFrame®, WinFrame®, VideoFrame®, MultiWin® und andere hier erwähnte Namen von Citrix-Produkten sind Marken von Citrix Systems, Inc.



HTML, DHTML, XML, XHTML sind Marken oder eingetragene Marken des W3C®, World Wide Web Consortium, Massachusetts Institute of Technology.



JAVA® ist eine eingetragene Marke der Sun Microsystems, Inc.



JAVASCRIPT® ist eine eingetragene Marke der Sun Microsystems, Inc., verwendet unter der Lizenz der von Netscape entwickelten und implementierten Technologie.



SAP, SAP Logo, R/2, RIVA, R/3, SAP ArchiveLink, SAP Business Workflow, WebFlow, SAP EarlyWatch, BAPI, SAPPHIRE, Management Cockpit, mySAP, mySAP.com und weitere im Text erwähnte SAP-Produkte und -Dienstleistungen sowie die entsprechenden Logos sind Marken oder eingetragene Marken der SAP AG in Deutschland und anderen Ländern weltweit. MarketSet und Enterprise Buyer sind gemeinsame Marken von SAP Markets und Commerce One.



Alle anderen Namen von Produkten und Dienstleistungen sind Marken der jeweiligen Firmen.



Die Verwendung der Screenshots wurde mit dem jeweiligen Eigner abgesprochen.

ABAP Course

André Bögelsack, Valentin Nicolescu

2

Agenda 1. 2.

ABAP Objects Business Server Pages • Maintenance and execution • Usage of BAPIs in BSPs • HTMLB • Model View Controller

ABAP Course

André Bögelsack, Valentin Nicolescu

3

Introduction ABAP Objects • Object-oriented enhancement of ABAP • Stepwise conversion of existing ABAP source code into ABAP Objects • Major tools: – ABAP Editor – Class Builder

ABAP Course

André Bögelsack, Valentin Nicolescu

4

Principles of Object Orientation I • Classes are the definition of an object including attributes and methods of this object • Objects are instances of classes – Example: • Class: Car • Instance: My car with the license number xxx

ABAP Course

André Bögelsack, Valentin Nicolescu

5

Use of classes and methods Procedurale approach

Object-oriented approach

Braking Car_accelerate Accelerate

Show_speed

Car_braking Car_show_speed

Car

Car_stop Car_Gear_change_up

Car_Gear_change_down

ABAP Course

Stop

Gear_change up Gear_change_down

André Bögelsack, Valentin Nicolescu

6

Principles of Object Orientation II • Encapsulation: The implementation of a class is invisible outside the class. Interaction takes place only by a defined interface. • Polymorphism: Identically-named methods used for different classes respond according to an appropriate class-specific behavior. • Inheritance: A new class can inherit attributes and methods from an existing class that can be extended by additional, own attributes and methods.

ABAP Course

André Bögelsack, Valentin Nicolescu

7

Example for Object Orientation Class Vehicle

Inheritance

Attributes:

Methods:

Inheritance

Create Show attribute

Class Motor Truck

Class Car Attributes: Manufacturer No. of wheels No. of seats Methods:

Manufacturer No. of wheels

Create Show attributes Used seats

Attributes:

Manufacturer No. of wheels Vehicle payload

Methods:

Create Show attributes Cargo capacity

Soure: Own illustration ABAP Course

André Bögelsack, Valentin Nicolescu

8

Classification of methods and attributes • Private  public – Private methods/attributes can be called/accessed only from the class‘ own methods (e.g. method „braking“ shouldn‘t be called by everyone) – Public methods/attributes can always be called/accessed (e.g. what colour has your car?)

• Instance  static – Instance methods/attributes exist for each instance of a class (e.g. method „get colour“, as each instance has it‘s own colour) – Static methods/attributes exist only once for all instances (e.g. listing of all instances of a class)

ABAP Course

André Bögelsack, Valentin Nicolescu

9

Declaration of a class • Classes can be created using ABAP Editor or Class Builder • Separation of definition and implementation of a class • Definition includes the declaration of all components of a class (e.g. methods, attributes..) • Implementation includes the coding for all methods of a class

ABAP Course

André Bögelsack, Valentin Nicolescu

10

Definition of a class CLASS DEFINITION. PUBLIC SECTION. METHODS: IMPORTING TYPE

TYPE TYPE

André Bögelsack, Valentin Nicolescu

11

Implementation of a class CLASS IMPLEMENTATION. … METHOD . …ABAP-Code… ENDMETHOD. … ENDCLASS.

ABAP Course

André Bögelsack, Valentin Nicolescu

12

Calling methods and accessing attributes • Instance method: [CALL METHOD] ->( = Value ). • Class method: [CALL METHOD] =>( = Value ). • Instance attributes: ->. • Static attributes: =>.

ABAP Course

André Bögelsack, Valentin Nicolescu

13

Constructor • Explicitly or implicitly defined method „constructor“ used for creating new instances • Automatically called by „CREATE OBJECT“ • In case of missing implementation simply a new instance is created • In case of explicit implementation within the PUBLIC SECTION additional steps can be executed when creating new instances (e.g. setting of default values)

ABAP Course

André Bögelsack, Valentin Nicolescu

14

Example constructor PUBLIC SECTION METHODS: constructor IMPORTING im_name type string im_planetype type string.

CREATE OBJECT r_plane EXPORTING im_name = ‚Munich‘ im_planetype=‚747‘.

ABAP Course

André Bögelsack, Valentin Nicolescu

15

Business Server Pages (BSP) • Web extension for ABAP • Enables the use of ABAP and server-side JavaScript within HTML pages created and hosted on a SAP System • Can be used for the realization of extensive portal solutions • Availability of BSPs starting with SAP Web Application Server 6.20

ABAP Course

André Bögelsack, Valentin Nicolescu

16

Maintenance and execution of BSP‘s • Maintenance by transaction SICF • Execution: http://:/sap/bc/bsp/sap/ \.htm E.g.: http://g51as1.informatik.tu-muenchen.de: 8051/sap/bc/bsp/sap/\.htm

ABAP Course

André Bögelsack, Valentin Nicolescu

17

Usage of BAPIs in BSPs I • Business Application Programming Interface = BAPI – – – – – –

BAPI represent an interface to the outside world SAP systems offer a wide range of different BAPIs BAPI calls are executed using RFC Transaction „BAPI“ shows all available BAPIs of the current SAP system Search for BAPIs using BAPI Browser, cross-system access possible Use of BAPIs with help of information available in the BAPI Browser

ABAP Course

André Bögelsack, Valentin Nicolescu

18

Usage of BAPIs in BSPs II Browser SAP System 1

SAP System 2 EXPORTING

BAPI

RFC

BSP

IMPORTING

• This example: Call of an external BAPI • Other possible examples: Call of an internal BAPI

ABAP Course

André Bögelsack, Valentin Nicolescu

19

Using BAPI Browser I • Call BAPI Browser in transaction SE80 – Menue item ‚Goto‘  ‚BAPI Browser‘

ABAP Course

André Bögelsack, Valentin Nicolescu

20

Using BAPI Browser II • BAPI Browser components: Interface definition RFCConnection

Available BAPIs for RFCConnection Call example

ABAP Course

André Bögelsack, Valentin Nicolescu

21

Usage of BAPIs in BSPs III Example scenario: • Call BAPI „BAPI_USER_GET_DETAIL“ – Show details of a certain user – BAPI offers broad functionality for query of user data – Use of BAPI in order to show the „last changed on“ date

ABAP Course

André Bögelsack, Valentin Nicolescu

22

Example: Call BAPI in BSP – Step 1 Step 1: Definition of variables • Temporary variables data username type c. data tmp_islocked type BAPISLOCKD. data tmp_moddat type BAPIMODDAT. • Interface variables data ISLOCKED type BAPISLOCKD. data LASTMODIFIED type BAPIMODDAT.

ABAP Course

André Bögelsack, Valentin Nicolescu

23

Example: Call BAPI in BSP – Step 2 Step 2: Definition CALL FUNCTION CALL FUNCTION 'BAPI_USER_GET_DETAIL' DESTINATION 'G11clnt101‚ EXPORTING ….. IMPORTING …... • • • •

CALL FUNCTION refers to the BAPI name DESTINATION refers to the RFC-connection EXPORTING refers to input parameters of a BAPI IMPORTING refers to output parameters of a BAPI

ABAP Course

André Bögelsack, Valentin Nicolescu

24

Example: Call BAPI in BSP – Step 3 Step 3: Complete call within a BSP: CALL FUNCTION 'BAPI_USER_GET_DETAIL' DESTINATION 'G51' EXPORTING username = 'master-adm' IMPORTING lastmodified = tmp_moddat.

• Query of the „Last changed on“ date (lastmodified) of user „master-adm“ • Output is assigned to variable tmp_moddat

ABAP Course

André Bögelsack, Valentin Nicolescu

25

Example: Call BAPI in BSP – Result • Result:

ABAP Course

André Bögelsack, Valentin Nicolescu

26

Example: Call BAPI in BSP • Complete source code:

User details