Sie sind auf Seite 1von 68

ABAP and Netweaver

Day 3
Hong Kong, China
3 7 July 2012
* Materials for this workshop are adapted from available resources from SAP UA

Agenda
ABAP Objects

BSP (Business Server Pages)


Web AS
BAPIs (Business Application Programming Interface)
BSP
MVC Architecture
Web Dynpro
Overview
Programming Web Dynpro

2012 SAP AG. All rights reserved.

ABAP Objects

Introduction ABAP Objects

Object-oriented enhancement of ABAP

Stepwise conversion of existing ABAP source code


into ABAP Objects

Major tools:
ABAP Editor
Class Builder

2012 SAP AG. All rights reserved.

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

2012 SAP AG. All rights reserved.

Use of classes and methods


Procedurale approach

Object-oriented approach

Braking
Car_accelerate

Show_speed

Accelerate
Car_braking
Car_show_speed

Car

Car_stop
Car_Gear_change_up
Car_Gear_change_down

2012 SAP AG. All rights reserved.

Stop

Gear_change up
Gear_change_down

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.

2012 SAP AG. All rights reserved.

Example for Object Orientation


Class Vehicle

Inheritance

Attributes:

Methods:

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

Create
Show attributes
Used seats

Manufacturer
No. of wheels

Inheritance

Create
Show attribute

Class Motor Truck


Attributes:

Manufacturer
No. of wheels
Vehicle payload

Methods:

Create
Show attributes
Cargo capacity

Soure: Own illustration

2012 SAP AG. All rights reserved.

Classification of methods and attributes

Private public

Private methods/attributes can be called/accessed only from the


class own methods (e.g. method braking shouldnt 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 its own colour)
Static methods/attributes exist only once for all instances (e.g. listing
of all instances of a class)

2012 SAP AG. All rights reserved.

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

2012 SAP AG. All rights reserved.

10

Definition of a class

CLASS <Class name> DEFINITION.


PUBLIC SECTION.
METHODS:
<Method1>
IMPORTING <Import Parameter1> TYPE <Data type>
<Import Parameter2> TYPE <Data type>
CLASS-METHODS:
<Method2>
DATA:
<Variable1> TYPE <Data type>
CLASS-DATA:
<Variable2> TYPE <Data type>
PRIVATE SECTION.
METHODS:
CLASS-METHODS:
DATA:
CLASS-DATA:
ENDCLASS.

2012 SAP AG. All rights reserved.

11

Implementation of a class

CLASS <Class name>


IMPLEMENTATION.

METHOD <Method name>.


ABAP-Code

ENDMETHOD.

ENDCLASS.

2012 SAP AG. All rights reserved.

12

Calling methods and accessing attributes

Instance method:

[CALL METHOD] <Instance name>


-><Method>( <Import parameter> = Value ).

Class method:

[CALL METHOD] <Class name>


=><Method>( <Import parameter> = Value ).

Instance attributes:

<Instance name>-><Attribute>.

Static attributes:

<Class name>=><Attribute>.

2012 SAP AG. All rights reserved.

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)

2012 SAP AG. All rights reserved.

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.

2012 SAP AG. All rights reserved.

15

BSP (Business Server Pages)

Web AS

BAPIs (Business Application Programming Interface)

BSP

MVC Architecture

Web AS
What is Web AS?

Web AS is a platform independent foundation for


writing applications for business.

2012 SAP AG. All rights reserved.

17

Web AS
What is Web AS?

It provides two runtime environment for executing


custom business applications.

2012 SAP AG. All rights reserved.

18

Web AS
What is Web AS?

Has toolkits and utilities to help develop scalable and


reliable business applications, with an emphasise on low
operating and upgrade costs.

It includes support for the ABAP language, the Java


language as show in the pervious slide.

In addition it includes the Web Dynpro environment.

2012 SAP AG. All rights reserved.

19

Web AS
What is Web AS?

The web Dynpro environment is used for creating web


applications, user interfaces and web services.
(*note* the web Dynpro environment will be expanded upon
in more detail in a different set of slides. )

2012 SAP AG. All rights reserved.

20

Web AS
How Web AS Works Incoming requests

You have incoming requests for data held by SAP R/3.


These requests can come in from BSP with HTML/ HTMLB
Web Dynpro, as well as web services, XML messages...

(*note* these are by no means all of the standards and


technologies that can request data from SAP using Web
AS)

2012 SAP AG. All rights reserved.

21

Web AS
How Web AS Works

Once SAP Web AS accepts the information form a


request it passes the information on to a program written in
either ABAP or Java which runs inside SAP Web AS.

These Programs can employ the assistance of toolkits


found within SAP that support workflow, archival and other
common business functions.

2012 SAP AG. All rights reserved.

22

Web AS
How Web AS Works

After accepting and processing the request Web AS


stores and retrieves the data requested from a database
using Open SQL.

2012 SAP AG. All rights reserved.

23

Web AS
Where Web AS fits in to NetWeaver

The major benefit of Open SQL is support for the most


popular databases, resulting in code that be portable and
flexible.

SAP Web AS has components available for managing


the life cycle of an application from cradle to grave.

2012 SAP AG. All rights reserved.

24

BAPI
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

2012 SAP AG. All rights reserved.

25

BAPI
Usage of BAPIs in BSPs II

Browser
SAP System 2
EXPORTING
BAPI

RFC

BSP

IMPORTING

This example: Call of an external BAPI


Other possible examples: Call of an internal BAPI
2012 SAP AG. All rights reserved.

26

BAPI
Using BAPI Browser I

Call BAPI Browser in transaction SE80


Menu item Goto BAPI Browser

2012 SAP AG. All rights reserved.

27

BAPI
Using BAPI Browser II

BAPI Browser components:


Interface
definition

RFCConnection

Available
BAPIs for
RFCConnection
Call example

2012 SAP AG. All rights reserved.

28

BAPI
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

2012 SAP AG. All rights reserved.

29

BSP
Business Server Pages

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

2012 SAP AG. All rights reserved.

30

BSP
Maintenance and execution of BSPs

Maintenance by transaction SICF

Execution: http://<host>:<ABAP Port>/sap/bc/bsp/sap/


<Program name>\<Page name>.htm

E.g.:http://uccwdisp2.fit.qut.edu.au:1097/sap(bD1lbiZjPTE
wMA==)/bc/bsp/sap/ztzbsp3/default.htm

2012 SAP AG. All rights reserved.

31

BSP
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.

2012 SAP AG. All rights reserved.

32

BSP
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

2012 SAP AG. All rights reserved.

33

BSP
Example: Call BAPI in BSP Step 3

Step 3: Complete call within a BSP:


data: list type BAPIRET2 occurs 0 with header line.
CALL FUNCTION 'BAPI_USER_GET_DETAIL'
EXPORTING
username
IMPORTING
lastmodified
TABLES
return

= 'master-adm'
= tmp_moddat.
= list

Query of the Last changed on date (lastmodified) of


user master-adm

Output is assigned to variable tmp_moddat

2012 SAP AG. All rights reserved.

34

BSP
Example: Call BAPI in BSP Result

Result:

2012 SAP AG. All rights reserved.

35

Complete source code:


<%@page language="abap" %>
<%@extension name="htmlb" prefix="htmlb" %>
<htmlb:content>
<htmlb:page title="Flugresultate" >
<table width="100%" height="100%" cellspacing="1" cellpadding="2" border="0">
<tr class="sapTbvCellStd"> <td bgcolor="Whitesmoke" valign="top">
<h2> User details </h2>
<%
data: username type c.

data ISLOCKED type BAPISLOCKD.


data: list type BAPIRET2 occurs 0 with header line.
data lastmodified type bapimoddat.
data tmp_islocked type bapislockd.
data tmp_moddat type bapimoddat.
CALL FUNCTION 'BAPI_USER_GET_DETAIL'
EXPORTING
USERNAME

= 'master-adm

TABLES
return

= list

IMPORTING
islocked

= tmp_islocked

lastmodified

= tmp_moddat.

%>

2012 SAP AG. All rights reserved.

36

<tr>
<td bgcolor="Whitesmoke" valign="top"> Master-Adm last modified? </td>
<td bgcolor="Whitesmoke" valign="top"><%= tmp_moddat %></td>
</tr>
<tr>
<td bgcolor="Whitesmoke" valign="top"> Master-Adm locked? </td>
<td bgcolor="Whitesmoke" valign="top"><%= tmp_islocked %></td>
</tr>
</table>
</htmlb:page>
</htmlb:content>

2012 SAP AG. All rights reserved.

37

BSP
HTMLB

Extension of HTML by SAP

HTML-Business
HTML-Business for Java
HTML-Business for ABAP

HTMLB is used e.g. for Enterprise Portal

2012 SAP AG. All rights reserved.

38

BSP
Comparison HTML / HTMLB

HTML

<%@page language=abap %>

<html>
<head>

<title>My BSP</title>
<% data: vari type i. %>
</head>
<body>
<%--This is a comment --%>
<% vari = 5 %>
In assigend
this coding
followingvari:
value
is
to variable
<%= vari %>
<br>
Thats it.
</body>
</html>

2012 SAP AG. All rights reserved.

HTMLB
<%@page language="abap" %>
<%@extension name="htmlb"
prefix="htmlb" %>
<htmlb:content design="design2003" >
<htmlb:page title=My BSP" >
<% data: vari type i. %>

<%--This is a comment --%>


<% vari = 5. %>
In this coding following value is
assigend to variable vari:
<%= vari. %>
<br>
Thats it using HTMLB.
</htmlb:page>
</htmlb:content>

39

BSP
HTMLB Statements
<%@extension name="htmlb" prefix="htmlb" %>

Naming of extension; in this case htmlb


<htmlb:content design="design2003" >

Begin of content-tags with explicit design definition


Standard designs: design2003, design2002 and classic
Design2003 can be used only for MS IE Version 5.5 or higher
<htmlb:page title="Meine BSP" >

Begin of page-tags with definition of title for BSP


Explicit <head> tag is not required any more
Explicit <body> tag is not required any more
</htmlb:page>
</htmlb:content>

Closing tags for page and content


2012 SAP AG. All rights reserved.

40

BSP
HTMLB Text fields

Text fields:

<htmlb:textView text = Hi this is a textView design


=Emphasized />

Text fields include different attributes:


Text: The displayed text
Design: Different design types
Emphasized
Header 1-3 - Headlines
Reference italic Reference
Standard
etc.

2012 SAP AG. All rights reserved.

41

BSP
HTMLB Forms, Input fields

Forms

<htmlb:form id = "myFormId" method = "post"


encodingType = "multipart/form-data" >
Equivalent of form in HTML

Input Fields

<htmlb:inputField id="IP1" />

Input field:

2012 SAP AG. All rights reserved.

42

BSP
HTMLB Buttons, Events

Buttons

<htmlb:button id = "SaveChanges" onClick


=
"SubmitChange" text = "Submit Button" onClientClick =
"onInputProcessing(htmlbevent);" />

Button for sending forms

Important: onClientClick raises event, in this case:


onInputProcessing(htmlbevent)

Event is called onInputProcessing

Event_id is called: htmlbevent

2012 SAP AG. All rights reserved.

43

BSP
HTMLB - Eventhandler

Events are defined in the Eventhandler!

2012 SAP AG. All rights reserved.

44

BSP
HTMLB RadioButtons I

Radiobuttons
<htmlb:radioButtonGroup id = "myID" columnCount = "2" >
<htmlb:radioButton id = "RBGenderFemale" text =
"female" tooltip = "I am female" disabled = "false" />
<htmlb:radioButton id = "RBGenderMale" text = "male"
tooltip = "I am male (and this button is disabled)" disabled =
"true" />
</htmlb:radioButtonGroup>
RadioButtons always belong to a RadioButtonGroup
RadioButtonGroup with attributes
Id: Unique ID
columnCount: Number of columns
currentItem: Defines the active item
2012 SAP AG. All rights reserved.

45

BSP
HTMLB RadioButtons II

<htmlb:radioButtonGroup id = "myID" columnCount = "2" >


<htmlb:radioButton id = "RBGenderFemale" text =
"female" tooltip = "I am female" disabled = "false" />
<htmlb:radioButton id = "RBGenderMale" text = "male"
tooltip = "I am male (and this button is disabled)" disabled =
"true" />
</htmlb:radioButtonGroup>
RadioButton with attributes
Id: Unique ID
Text: Text of RadioButtons
Tooltip: Text that is displayed as tooltip
Disabled: RadioButton cannot be selected
2012 SAP AG. All rights reserved.

46

BSP
HTMLB - Layout

RadioButtons

Tree with treeNodes

TabStrips

TableView

2012 SAP AG. All rights reserved.

47

BSP
Model View Controller

Up-to-now: Presentation logic and application logic both are


included in a BSP

Model View Controller: Separation between logical layers

SAP System

SAP System
Model

BSP
Controller
View
2012 SAP AG. All rights reserved.

48

MVC Architecture

Model
Interface to the backend system
Enables data access for the Web Dynpro application

Controller
Controls

interaction between Model and View


One Web Dynpro application can include different controller

View
Responsible

for the data presentation


Each Web Dynpro application has at least one view
2012 SAP AG. All rights reserved.

49

BSP
Model View Controller

Model
Consists of a class derived from CL_BSP_MODEL
Processing takes place in background
Controller
Handles Requests and forwards to Model
View
Calls Controller
Only responsible for
the visualization of data

SAP System
Model
Controller
View

2012 SAP AG. All rights reserved.

50

BSP
Model View Controller - Example

No
direct call

HTTP-Request

SAP System
Controller
example_co.do

DO_REQUEST
Model
ZCL_BSP_MYMVCTEST

Attribute
NAME

View
view_test.htm

Application logic
2012 SAP AG. All rights reserved.

51

BSP
Model View Controller - Example

Create Controller example_co.do

Derive own class ZCL_BSP_MYMVCTEST from


CL_BSP_CONTROLLER2

Redefine method DO_REQUEST

Define view view_test.htm

Define attribute NAME

Call Controller

2012 SAP AG. All rights reserved.

52

BSP
Model View Controller - Example

2012 SAP AG. All rights reserved.

53

Exercise 9

ABAP Objects and Business


Server Pages

2012 SAP AG. All rights reserved.

54

Web Dynpro

Overview

Programming Web Dynpro

Web Dynpro
Overview

Objectives of Web Dynpros:

Model based UI development

Future proof UI declaration

Central implementation of UI standards

Support of major platforms (ABAP as of NW 7, JAVA as


of NW 2004)

2012 SAP AG. All rights reserved.

56

Web Dynpro
Web Dynpro Component

Window
One or more views
Navigation links
View
UI elements
Plugs enable navigation between
views
View Controller
Processing user input
Access context data
Component Controller
Visible for all component controllers
Interface Controller
Visible for all component controllers
Also visible outside the component

2012 SAP AG. All rights reserved.

Web-Dynpro-Component
Component
Contoller
Context
Events
Methods

Interface
Contoller
Context
Events
Methods

Window
View
Contoller
Events
Methods
View
Context
Plugs
UI Elements Actions
View Container

Source:
http://help.sap.com/saphelp_nw70/helpdata/en/7c/3545415ea6f5
23e10000000a155106/frameset.htm

57

Web Dynpro
Web Dynpro View

View Designer
UI Element Category

Smallest visible unit of a Web


Dynpro application
Include different UI elements,
like tables, textfields, or input fields
View Designer enables drag &
drop of UI elements
UI Element Hierarchy determines
order and nesting of UI elements
UI Element properties and
actions are listed in the properties
table

Layout

Element 1
Element 2
Element 2a

UI Element Hierarchy
ROOT UI ELEMENT
CONTAINER

Element 1
Element 2
Element 2a
Element 2b

Element 2b

Properties:
Element 2a

Source:
http://help.sap.com/saphelp_nw70/helpdata/en/7c/3545415
ea6f523e10000000a155106/frameset.htm
2012 SAP AG. All rights reserved.

58

Web Dynpro
View Context and Data Binding

View context structures and stores application data of a view


Hierarchical data structure, using CONTEXT as root node
Context attributes include name and data type of attribute
UI properties are linked to context elements by data binding
Data binding of a UI element property is set up in the view
layout
Data transfer between views is realized by the global context

View 1
View Layout

View Context

CONTEXT

Input 1
Input 2

2012 SAP AG. All rights reserved.

Component Controller
Context

CONTEXT

View 2
View Context

CONTEXT

Table SPLFI
Table
SPLFI
Carrid
Connid
Cityfrom

Carrid
Connid
CITYFROM
Table SFLIGHT

View Layout
C1 c2

c3

Table
SPLFI
Carrid
Connid
Cityfrom

59

Web Dynpro
View Controller - Event Handler

UI elements (e.g. Button) can contain actions

Actions are triggered by user activities (e.g. click


on Button)

Actions are processes by the event handler of the


view controller

Each action is linked to exactly one event handler


method

Event handler methods have the prefix


ONACTION followed by the action name defined
within an UI element
2012 SAP AG. All rights reserved.

60

Web Dynpro
Component Controller

Each Web Dynpro component contains exactly one


component controller
Contains context, events, and methods
Visible for all views of a component
Context mapping = Link between view context node and
component controller context node
Web Dynpro Component
Component Controller
View Controller 1

2012 SAP AG. All rights reserved.

View Controller 2

61

Web Dynpro
Controller Methods
Method

Description

Availability

WDDOEXIT

Cleanup method of the controller

All controllers

WDDOINIT

Initialization method of the controller,


runs the first time the controller is
called

All controllers

WDDOBEFOREACTION

Implement own validations before an


action is triggered

View controller

WDDOAFTERACTION

Called for all visible views at the time


an action is executed

View controller

WDDOBEFORENAVIGA
TION

Error handling before the navigation


through the application

Component
controller

WDDOPOSTPROCESSI
NG

Handling of errors that occurred


during the context validation

Component
controller

WDDOMODIFYVIEW

Method for modifying the view before


rendering

View controller

2012 SAP AG. All rights reserved.

62

Web Dynpro
User input

Data Container
Data is accessible
only at runtime

my name

Client

Validation
of user input

assigned
Controller Context
WDDOBERFOREACTION

Error message

Event handling
validation Indep.
handlers

standard
handlers
WDDOAFTERACTION

WDDOBEFORENAVIGATION
Navigation and View initialization
View modifying WDDOMODIFYVIEW
WDDOPOSTPROCESSING

Rendering
2012 SAP AG. All rights reserved.

if validation failed

Source:
http://help.sap.com/erp2005_ehp_04/helpdata/EN/d2/8acd409cc4dd50e100
00000a1550b0/frameset.htm

Controller Methods

63

Web Dynpro
Controller Attributes

WD_CONTEXT
Reference to the root node of the context of the
controller
Used to edit the content of a context node in a
controller method
WD_THIS
Reference to the local controller interface
Used to access methods and attributes of the local
controller interfaces

2012 SAP AG. All rights reserved.

64

Web Dynpro
Web Dynpro Window

Web Dynpro component includes at least one


window
Navigation between views can be set up in the
window
To set up navigation between two views, you must
create an inbound plug for one view and an outbound
plug for the other view.
Window
View
SELECT_DATA

View
DISPLAY_DATA

Outbound
Plug

2012 SAP AG. All rights reserved.

Navigation Link

Inbound
Plug

65

Web Dynpro
Exercise: Flight data application
Web Dynpro Component
Window
View MAIN

View ADD_INFO

Component Controller
Context

Controller Methods

oBAPI_FLIGHT_GETLIST
-- IMPORTING
Airline
-- CHANGING
Flight_List
Additional_Info

o EXECUTE_BAPI_FLIGHT_GETLIST

2012 SAP AG. All rights reserved.

o GET_ADD_INFO (Supply Function)

66

Exercise 10

Web Dynpro

2012 SAP AG. All rights reserved.

67

Thank you

Contact information:
Taizan Chan
t.chan@qut.edu.au

Das könnte Ihnen auch gefallen