Document 2
Document 2
Document 2
For information about creating BSP applications, see the various tutorials (Creating Web
Applications with BSPs) and the documentation on Web Application Builder, specifically the
sections under Basic Functions.
From SAP Web AS 6.20, when you create a BSP application in the Web Application Builder,
this type of node is created and activated in the appropriate part of the ICF service tree (see
also Creating an ICF Service). If necessary, you can add permissions for this node (see
also Service Options).
For BSP applications that were created before SAP Web AS 6.20 and which therefore do not
have any nodes in the ICF service tree, this node is generated automatically by the system as
soon as you branch to the corresponding BSP application in change mode.
There may be conflict with old BSP applications with names that are
longer than 15 characters. Before SAP Web AS 6.20 you could
create BSP applications whose names could exceed the length of the
service name in Transaction SICF. In this case, we recommend that
you copy all of the old BSP application to a new BSP application with
a shorter name, so that the node is automatically created.
BSP Tutorials
Purpose
To learn how to create Web applications with Business Server Pages, you can work
through the simple tutorials that build on each other. You should be able to run
through all of the steps described here in your own system.
If you want to develop Web applications with BSPs, your system must meet the
following requirements: Prerequisites for Creating Web Applications.
The following tutorials are available:
1. • First Tutorial: First Steps with Business Server Pages…
2. • Second tutorial: A Small BSP Application and A Small BSP Application with
HTMLB
3. • Third tutorial: Our First Online Bookshop
4. • Fourth tutorial: Further Developing the Bookshop
5. • A small Tutorial is also available for your first steps with the Model View
Controller design pattern.
6. • For a more complex MVC tutorial based on the third tutorial, see: Our Little
Online Bookshop Using MVC and HTMLB
You can also read the reference documentation on the SAP Web AS
Architecture, which explains the system’s architecture and components:
Features
In this tutorial you will learn how to:
• Create a BSP Application with one page
• Create HTML code with dynamic script in ABAP
• Insert a graphic (MIME object)
• Display the activated page in the Web browser
The application class is a regular ABAP Objects class. As such, the application class can
include any methods, attributes, and events the developers wants.
The application class is usually used to store data and make it available across BSP pages.
This data is stored as attributes. In addition, the application class encapsulates BSP
application logic in methods. This allows several BSP applications to use the same
application class and provide one business application that contains different interfaces, such
as for various devices, without having to replicate the business or application logic.
This also means the global Object application can be used in the BSP application to access
the attributes and methods of the application class.
You do not have to use an application class in your BSP application. It is an optional way for
you to structure your BSP application.
You use the Web Application Builder in transaction SE80 to assign an application class to a
BSP application.
A simple example of where an application class could be useful would be a
class for controlling dialog logic and maintaining data consistency in a BSP
application for shopping. This application class would include a shopping
basket (internal table or other object) as an attribute. There would also be
methods for changing and processing the shopping basket, such as to add,
change, or delete articles. Methods for determining prices, creating offers,
and posting orders would also be helpful.
For an example of the use of an application class, see Extending the Online
Bookshop.
Runtime Behavior
Any ABAP Objects class can potentially be used as an application class of a BSP application.
However, the BSP runtime environment must treat the class as a singleton, that is, a class for
which there is only one instance per session.
The lifetime of an application class depends on the state model of the BSP application. A BSP
application can be stateful or stateless.
In stateful mode, the application class provides local buffering for data sets that are difficult to
determine.
In Stateless BSP Applications, the application context (roll area) is only available for the
lifetime of a single request and is released at the end of the request. When the application
context is released, all data and objects held by the session on the application server are also
released. This includes the application object.
This means the lifetime of the application object starts when the request is received and ends
when a response is sent. The application objects is not available across several pages. Each
page and each request interacts with a different instance of the application class.
In stateless mode, the application object cannot hold data across requests. For stateless
applications, application classes are usually used to store the business logic in methods, but
do not buffer data.
Otherwise there are no other restrictions. You do need to ensure that the internal
implementation of methods is chosen correctly, depending on the state mode where the class
is implemented. For stateless applications, for example, it would be useless to implement
expensive data gathering routines as these would be lost after every request. Instead, just get
the exact data you need at that time. In stateful applications, you can implement an
initialization phase where you get a large amount of data at one time, which can improve
performance.
See also:
As the application object is an application attribute in every BSP event handler, the
methods of the CL_BSP_APPLICATION class are also available with the corresponding
inheritance. This makes it easy to provide the relevant functionality to lower application levels
using a single object reference.
See also:
You can find details of basis class CL_BSP_APPLICATION in the reference documentation:
Class CL_BSP_APPLICATION
BSP Components
Business Server Pages (BSPs) are HTML pages that contain the actual application logic and
presentation logic. BSPs define the Web user interface and determine the elements of user
interaction.
Page attributes are visible in the layout processing as well as in the event handlers of a page.
They can be used to store data obtained in the standard handler OnInitialization, and to make
this data accessible for the layout processing and the other event handlers.
Similar to every object in the SAP System, BSPs also have different administration attributes.
BSP Directives
Overview
BSP directives are enclosed in tags: <% Directive %>
The directives described in the following sections are supported by Business Server Pages
(BSP). The syntax is compatible with the familiar server page technology.
• Page Directive
• Inline Code
• Comments
• Include Directive
• OTR Directives
• Extension Directive
You use the Tag Library to add BSP directives to your code using
Drag & Drop.
For more information see Transferring Variables.
Special Programming Features
The following code sections for the layout of a BSP are not equivalent:
<% read table itab index lv_index. %>
<% if sy-subrc ne 0. clear workarea. endif. %>
and:
<% read table itab index lv_index.
if sy-subrc ne 0. clear workarea. endif. %>
The first code extract above contains a function module call between the two ABAP
commands. The second code extract does not:
....
* BSP SCRIPT source
read table itab index lv_index.
* BSP STATIC source
* HTML begin: #### ######
CALL METHOD %_IF_PM->ADD_STATIC_REF
exporting
encoding = 0
source = %_HTML_POOL
offset = 0000018407 length = 0000000039 .
Page Directive
Definition
This directive is used to specify the script language.
otrTrim
From SAP Web AS 6.20 Support Package 7, the attribute otrTrim is also available for the
page directive.
This attribute is a boolean value, that is, it can have the values TRUE and FALSE. The default
value is FALSE. If it is set to TRUE, all OTR texts on a page are condensed by removing all
blank characters from the start and end of a string.
[ test line ]
[ before test middle test end. ]
[This is a test for an alias text]
Inline Code
Definition
With this directive you can embed the script code into the page.
The inline code is written in the language specified with the Page directive.
Unlike code that includes HTML comments, server-side comments are not included in the
page sent to the client /browser.
When you use HTML comments, however, they require longer processing times as well as
larger bandwidths. This is why you should not use HTML comments with BSPs or views.
Include Directive
Definition
With this directive you can paste in existing pages or pages fragments into the page.
Enter the URL of the page to be pasted in relative to the URL of the current page.
OTR Directives
Definition
The Online Text Repository (OTR) is a repository for all HTML texts, which are accessed
using an alias. OTR texts can be translated into other languages using translation tools. At
runtime, the OTR directive is replaced by the text defined for the logon language.
Use
There are two ways of using the OTR.
1. You can first write the text in the OTR and give it an alias that should be as
meaningful as possible.
Then you can display the text with the following syntax: <%=otr(alias)%>.
2. You can however also specify the text in the page layout:
Extension Directive
Definition
You can use the extension directive to import a BSP extension into your BSP. As a result you
can access all elements of the extension in your BSP. The extension directive is always
located immediately after the page directive.
The prefix is used as the namespace for all elements in the BSP extension. The prefixes sap
and bsp are reserved.
See also:
BSP Extensions
Global Objects
Certain global objects can be accessed from all parts of a BSP (initialization, layout, input
processing). For example, the request and response object, the application object (if an
application class was defined for the BSP application), the navigation object, and the runtime
object, can be accessed.
• Object application
• Object navigation
• Object messages
• Object runtime
• Object request
• Object response
• Object page
• Object page context
The objects and their signatures for the individual event handlers are
displayed if you choose in the Web Application Builder.
Example:
Class CL_BSP_APPLICATION
Overview
Class CL_BSP_APPLICATION is an optional superclass for BSP application classes. Each
application has the option of deriving its own application class from CL_BSP_APPLICATION .
If the application class has not already been derived in an inheritance hierarchy, we
recommend that it is derived from CL_BSP_APPLICATION .
Class CL_BSP_APPLICATION has methods that are typically required by a BSP application
for embedding in a Web environment. This is how information about the current BSP
application (such as session timeout, current URL of BSP application, state mode and so on)
can be called or set.
See Also:
• IF_BSP_APPLICATION
• Object application
Class CL_BSP_MESSAGES
Overview
You can use class CL_BSP_MESSAGES in BSPs for outputting error and information
messages.
You can flag each message with a condition that serves as a key for the message. The effect
of this is that a message is only output in a BSP if the pertinent condition is fulfilled. This
makes it easy to place input-specific messages directly beside the relevant input fields.
Each BSP has an instance of this class that contains the current messages of the class. The
object is reset after every HTTP request/response cycle. The object is accessed from a BSP
via the parameter page of the event handler as page->messages or via the self-reference
me in the form of interface qualification me->if_bsp_page~messages.
Implemented Interface
Superclass
Attributes
Methods
Method add_message
Return Values/Exceptions -
Method assert
Example:
...
<% if page->messages->assert( 'invaliduser' )
<> 0. %>
<img src="stop.gif">
<%= page->messages->assert_message(
'invaliduser' ) %>
<% endif %>
…
Method assert_message
Method assert_severity
Method get_message
Method num_messages
Parameters -
Class CL_BSP_SERVER_SIDE_COOKIE
Overview
Class CL_BSP_SERVER_SIDE_COOKIE provides methods for setting, getting, deleting, and
managing cookies on the server.
Server-side cookies are persistent data, similar to the usual client-side cookies. However,
while on the client-side, there are restrictions that limit the size of cookies to around 4
kilobytes per cookie, the number of cookies to 300 in total and 20 per server or domain,
server-side cookies are subject to no such restrictions. A server-side cookie is stored on the
database.
For technical reasons, each individual cookie can be stored in one of the following ways:
• as a field or
• as a structure or
• as an internal table
When you get a cookie, please note that it must be returned to the
same data structure. Otherwise, an error will occur, which you can
query using an error method.
The parameters username and session_id deserve special attention. Setting username
to sy-user is ambiguous in cases where an application is started by an anonymous user
stored on the server. It would be better to use session_id (see example) since runtime-
>session_id indicates the browser session.
When you design an application, you should give careful consideration to whether the
application should be stateless and the required context data be retained from page to page
in cookies (client-side or server-side), or whether the application should be stateful. A stateful
application makes sense when there is a large amount of context data that would otherwise
have to be read from or written to the database using cookies and thus slow down
performance (see also Stateful or stateless programming?).
The program BSP_SHOW_SERVER_COOKIES provides an overview of all of the cookies set in
the system. The program BSP_CLEAN_UP_SERVER_COOKIES deletes all expired cookies to
the day.
The system administrator should schedule the program
BSP_CLEAN_UP_SERVER_COOKIES to run in the background on a
regular basis.
Class CL_BSP_SERVER_SIDE_COOKIE is contained in the package SBSP_RUNTIME.
Inheritance Hierarchy/Interface Composition
Implemented Interface
-
Superclass
-
Attributes
Attribute Name Declaration Type Description
Methods
SESSION_ID Session ID
SESSION_ID Session ID
SESSION_ID Session ID if
required
Parameters RC Returncode
data: rc type i,
txt type string.
rc = cl_bsp_server_side_cookie=>get_last_error( ).
Method get_last_error_name
Signature method GET_LAST_ERROR_NAME
importing
NAME
data: rc type i,
txt type string.
rc = cl_bsp_server_side_cookie=>get_last_error( ).
if rc ne 0.
txt =
cl_bsp_server_side_cookie=>get_last_error_name( ).
endif.
Method get_server_cookie_info
Signature method GET_SERVER_COOKIE_INFO
exporting
COOKIES
APPLICATION_NAMESPACE
APPLICATION_NAME
SESSION_ID
USERNAME
NAME
SESSION_ID Session ID
Class CL_BSP_GET_TEXT_BY_ALIAS
Overview
Class CL_BSP_GET_TEXT_BY_ALIAS provides a method to fetch OTR alias texts.
Implemented Interface
Superclass
Attributes
-
Methods
Method GET_TEXT
Description This method fetches an OTR alias text for a specified OTR
alias name.
report OTRTEST.
write / TEXT.
Class CL_BSP_CONTROLLER2
Overview
Class CL_BSP_CONTROLLER2 is used to create controllers and components. Every controller
class automatically inherits all methods and attributes from this central basic class.
If the basic class of your controller class displays
CL_BSP_CONTROLLER instead of CL_BSP_CONTROLLER2, change
the inheritance hierarchy accordingly.
Methods
Below you can find an overview of all methods in a controller class. Processing Process
provides details on the most important methods.
The individual methods can be separated into different categories:
Functions where overwriting is required
DO_REQUEST is the central method in a controller class.
• If it is the top-level controller of a component, then this method handles both input
and output processing.
Service functions
You can call these methods:
Method Description
GET_LIFETIME Returns the lifetime of this page (only for the top-level
controller)
SET_LIFETIME Changes the lifetime of this page (only for the top-
level controller)
• Browser cache
• Server cache
Framework functions
These methods are provided as part of the framework and are only included here for the sake
of completeness. They are not usually relevant for application development.
Method Description
Examples of Architecture
Previous BSP Application
With SAP Web AS 6.10, normal BSP applications usually consisted of an application class
and several BSPs. Navigation between the pages was controlled using redirects.
This is how it looks with SAP Web AS 6.20: BSP Application with Controllers and Views
In this tutorial you can use a simple example to run through the first steps with the Model
View Controller design pattern for BSP.
Prerequisites
• You are in an SAP Web AS 6.20 system
• You know how to use MVC for BSPs
Functions
Creating a Controller
Creating a View
Calling a Controller
Creating a Controller
Prerequisites
You have created an empty BSP application for this tutorial.
Procedure
1. Create a controller within your BSP application.
2. On the following dialog box, give the controller a name and add a short description.
3. Choose .
4. On the following screen, assign a class name to the controller.
If the class does not already exist, the system asks you if you want to create it.
Choose Yes so that you create a class with the specified name that is derived from
CL_BSP_CONTROLLER2.
method DO_REQUEST .
write( '<html><body><H1>' ).
write( '</H1></body></html>' ).
endmethod.
11. You can now test the new controller page that you have created.
Result
If you do not always want to use the write function to create the HTML page
content (as described in Creating a Controller), and you want to create it as pure
HTMLO layout instead, then create a view that you can call from the controller.
Procedure
...
1. Begin as if you are creating a normal page with flow logic in your BSP application.
To do this, choose Create → Page.
2. In the following dialog box, enter a name and short description of the view and
select View as the page type:
3. Choose .
4. Create the attributes for the variable parts of the view.
You cannot define auto-page attributes, since views cannot be called directly from the
browser.
Create the following attribute:
<html>
<head>
<link rel="stylesheet"
href="../../sap/public/bc/bsp/styles/sapbsp.css">
</head>
<body class="bspBody1">
<H1>View Example</H1>
</body>
</html>
6. Activate the view.
7. Finally, adjust the DO_REQUEST method to the controller class.
Here, the schema is always the same. First you create the view, then you set the
attributes, and then you call the view. (For the time being you can ignore the warning
concerning exception CX_STATIC_CHECK, or you can set a try-catch block around
the calls):
method DO_REQUEST .
call_view( main_view ).
endmethod.
8. Activate your class and test your controller.
Result
Creating a View
Use
If you do not always want to use the write function to create the HTML page
content (as described in Creating a Controller), and you want to create it as pure
HTMLO layout instead, then create a view that you can call from the controller.
Procedure
...
1. Begin as if you are creating a normal page with flow logic in your BSP application.
To do this, choose Create → Page.
2. In the following dialog box, enter a name and short description of the view and
select View as the page type:
3. Choose .
4. Create the attributes for the variable parts of the view.
You cannot define auto-page attributes, since views cannot be called directly from the
browser.
Create the following attribute:
<html>
<head>
<link rel="stylesheet"
href="../../sap/public/bc/bsp/styles/sapbsp.css">
</head>
<body class="bspBody1">
<H1>View Example</H1>
</body>
</html>
6. Activate the view.
7. Finally, adjust the DO_REQUEST method to the controller class.
Here, the schema is always the same. First you create the view, then you set the
attributes, and then you call the view. (For the time being you can ignore the warning
concerning exception CX_STATIC_CHECK, or you can set a try-catch block around
the calls):
method DO_REQUEST .
call_view( main_view ).
endmethod.
8. Activate your class and test your controller.
Result
Calling a Controller
Use
You can call a controller from a page with flow logic, or from a view.
Procedure
1. Create a page within your BSP application.
Ensure that you select Page with Flow Logic as the page type.
2. In the Tag Browser, select BSP extension bsp and drag it to the second line of your
BSP’s layout under the page directive.
3. Now drag the <bsp:goto> directive of BSP extension bsp to the body of the HTML
layout and add the URL parameter.
<%@page language="abap"%>
<html>
<head>
<link rel="stylesheet" href="../../sap/public/bc/bsp/styles/sapbsp.css">
<title> Initial page </title>
</head>
<body class="bspBody1">
<bsp:goto url="example.do"></bsp:goto>
</body>
</html>
<html>
<head>
</head>
<body class="bspBody1">
</head>
<body class="bspBody1">
<H1>View Example</H1>
</body>
</html>
5. You can now try out the difference between the <bsp:goto> element and the
<bsp:call> element.
If you use the <bsp:call> element instead of the <bsp:goto> element, the calling
page text remains the same. In the view that is inserted, you should therefore delete
the HTML text available on the outline page, otherwise these texts will be transferred
twice.
6. You can add another attribute to the controller. This is a public class attribute.
It is set using the <bsp:parameter> element. You can use it for example to control
which view is called, or this value can be passed to the view.
Online Bookshop
The BSP application that you create in these tutorials is an online bookshop. The first page
(entry page) of the bookshop should look like this:
In this application you will learn to create BSPs as page fragments and to include them in
other BSPs using include statements. This ensures that all the headers in your BSPs are
identical. You will also learn to work with ABAP methods for data retrieval. The methods used
here are part of the package SBOOKSHOP, which is described in the section Data Model.
To search for a book, the user chooses the link search book:
Processing Process
The internal structure illustrated below underlies the BSP application with the interface just
described:
The arrows represent navigation paths between the pages.
For information on the data model in the SAP System, see section Data Structures.
For information on "clean" and efficient programming, see the section Separation of Data
Retrieval, Evaluation, and Output.
Now you can get started with creating your BSP application.
Get started!
In this tutorial, the book search facility demonstrates the advantages of clearly separating
data retrieval, evaluation, and output:
• The page attributes for the results page are set in the OnInputProcessing of the
search page. If nothing was input, the results page should not be opened.
• The layout part, then, simply checks whether or not this table is empty. If it is empty,
this means that no matching entries were found. If the table is not empty, the results
are output in a HTML table.
This ensures that functionality and logic (error handling) are kept out of the layout part.
In the package SBOOKSHOP in your system, you will find the following database tables and
other objects used in the tutorials. Only the most important objects are listed here. For a
complete list, see the Object Navigator in your system.
Database Tables
SBOOKSHOP contains the following database tables:
CURRENCY
COUNTRY
USRPWD
KEYWORD
PUBLISHER Publisher
ISBN ISBN
NEW_ENTRY Indicator
ISBN ISBN
ISBN ISBN
Flag Indicator
Symbol Meaning
Import parameter
Export parameter
Return parameter
Procedure
Take the following steps to create a page fragment for your BSP application:
1. In the Web Application Builder, open your application (tutorial_3), position your
cursor on the highest-level hierarchy node in the left-hand navigation tree, and, using
the right mouse button, choose Create → Page .
2. In the popup that appears, enter a meaningful name (the system will propose the
extension .htm) and a description, and select the page type Page Fragment.
3. Choose .
4. Create the code for your page fragment.
<html>
<head>
<title>mySAP Bookshop</title>
</head>
<hr>
5.
6. Make sure that you do not include the end tags </body> and </html> in this code,
as this is a page fragment, and page fragments are always located at the beginning
of the HTML page. Correspondingly, page that include the fragment head.htm have
no start tags, only end tags.
7. This ensures that the headers that are included in every BSP by means of the steps
outlined below always look the same:
8.
9. This also sets the background color for the whole page.
10. Choose .
Result
In the Web Application Builder your entire BSP application with the pages, images, and page
fragment are displayed:
Layout for the First Page
<p>
<p>
<a href="about.htm">about</a><br>
</body>
</html>
This code uses HTML to create three links, and uses the include directive (see below). The
first link links to the list of authors, which you created in the previous tutorial (see A Simple
BSP Application). The second link links to the search page, and the third link links to an
information page.
This directive includes the page fragment head.htm in the page default.htm. This has the
effect that the first page gets the header defined in head.htm.
The include directive includes existing pages and page fragments in the BSP. Make sure
that you always use a relative URL when specifying the page to be included.
If you view the page default.htm in the browser and choose View
Source, you will see that the HTML code simply consists of
head.htm and default.htm.
Layout for the Info Page
<p>
<table>
<tr><td> <h3>Demo bookshop for BSP tutorial</h3></td></tr>
<tr><td> <h4> © by SAP AG 2000.</h4></td></tr>
<tr><td> <img height="10" src="blind.gif"></td></tr>
</table>
</body>
</html>
<tr>
</small></td>
</table>
</body>
</html>
First, this code checks whether there are any entries in the structure bookcat_tab that
match the search criteria. If there are not, an error message is output. The user can then click
on a link on the error page to return to the search page.
If there are matching entries in the bookcat_tab structure, the results are output in a four-
column table.
A loop statement writes the content of the internal table bookcat_tab line by line into a
help variable. When this happens, the title and sub-title for each book are stored along with a
link. The variable ?s_cata_id is included in the link after the page details.
Next, the first name and surname of the author, the delivery time, and the price are retrieved,
and all this data is written to the table. The variable s_cata_id contains the unique ID
number of a book in the catalog. This ID number is the primary key of the database table
bscatalog in the SAP System (see Data Model).
These attributes are the fields that are used to search on the search page. They also
correspond to the import parameters of the method search_book in the SAP System (see
also Data Model). These attributes are flagged as automatic, as they were set using
navigation->set_parameter on the search page, and now variables of the same name
are being used again. There is also the page attribute bookcat_tab. This is the table in the
Data Dictionary that contains the book and catalog data for the tutorials. This table is not
flagged as an automatic page attribute, as it is being used for the first time.
Auto page attributes can have various data types, structures or tables
but no references.
OnInitialization
data: isbn_tab TYPE isbn_tab.
if sy-subrc = 4.
navigation->goto_page( 'invalid_isbn.htm' ).
elseif sy-subrc <> 0.
navigation->goto_page( 'error.htm' ).
endif.
IF sy-subrc = 0.
CALL METHOD cl_book_shop=>get_book_data
EXPORTING
isbn_tab = isbn_tab
IMPORTING
bookcat_tab = bookcat_tab
EXCEPTIONS
empty_input_table = 2
invalid_isbn = 4.
ENDIF.
The data statement sets the data transfer for the ISBN table.
The method search_book of the class cl_book_shop is used to search for book titles that
match the user input. When this happens, the method search_book gets the page
parameters author, title, publisher, isbn and keyword, and the parameter
isbn_tab is returned with the results of the search. The following exceptions or errors are
defined in search_book:
• There are no search parameters, that is, the user input fields are empty (sy-
subrc=2).
Navigation Structure
In our example, the navigation structure is important mainly for the search function.
When the user enters search criteria on the search page (search.htm), a
corresponding results list (results.htm) is output. The navigation request
TORESULTS controls the navigation procedure that opens the results page.
When the user orders a book on the page showing detailed information on individual
books (showbook.htm), the page containing a confirmation of the order
(corder.htm) is displayed. The navigation request TOORDER controls this
navigation procedure.
The navigation structure for your BSP application, which you set using the tab page
Navigation, looks like this:
You have now created your own online bookshop as a BSP application. Once you
have activated all the BSPs and the BSP application itself, call your application in the
Web browser.
To Be Continued...
In the next tutorial you will extend your online bookshop by adding an online shopping
basket with cookies, and a function for creating new users.
Our Little Online Bookshop Using MVC and
HTMLB
Purpose
In this tutorial we create the same online bookshop as in Tutorial 3 ( Our First Online
Bookshop) but this time using MVC and HTMLB.
Introductory Comments
This has the advantage over the previous BSP application that you have several
components on one page, where each component is represented by a controller and a
view.
You should do this tutorial if you are used to creating BSP applications (ideally once
you have completed all of the tutorials) and you want to use MVC and HTMLB to
create your applications. You should also have already completed the short Model
View Controller Tutorial.
Integration
Each tutorial builds on the information presented in the previous one.
You can also read the reference documentation on the SAP Web AS Architecture,
which explains the system’s architecture and components:
You can find documentation about the MVC Design Pattern in Model View
Controller (MVC).
You can find documentation on BSP extension HTMLB in the system: you can
display detailed documentation for each HTMLB element in the Tag browser of the
Web Application Builder.
Features
In this tutorial you will learn how to:
• Recognize HTMLB elements TableView, Button, Tray, Group and so on.
• How to create a page (view) that calls several sub-controllers
• How you implement event handling with MVC
• How you can control the rendering of individual cells in a table
Section Bookshop Structure describes how you set up the BSP application to be
created.
See Creating BSP Applications, Controllers and Views for the exact procedure.
Constraints
This model does not explain the use of models; for this comparatively simple
application you need controllers and views only.
The tutorial ends without any defined error pages. You can find information about
using and creating error pages in the MVC documentation in Creating Error Pages.
Bookshop Structure
Unlike the online bookshop without MVC, this bookshop is structured so that book searches,
results lists and the detailed displays are summarized on one page.
You can use this to clearly show how the MVC programming model "thinks".
If you call the URL hidden behind the main controller in the browser, the following page is
displayed:
Tha main controller bookshop.do calls view default.htm.
This contains a page fragment, which represents the bookshop header (like Tutorial 3 but with
HTMLB), as well as 3 HTMLB trays, which call the corresponding controllers.
The following graphic highlights the structure.
The URL is recognized by the SAP Web AS as a BSP application and is processed by the
BSP runtime. This calls main controller bookshop.do up first, that is, method DO_REQUEST
for the corresponding controller class is executed. This then calls the main view
default.htm, which in turn uses <bsp:call> element within HTMLB trays to call sub-
controllers search.do, result.do and detail.do. These sub-controllers have views that
they call.
• A BSP application
• Next controller
bookshop.do. This is the main controller that is also called using the URL
by the browser. Method ON_REQUEST of the controller class of this controller
is executed first of all. This calls the view default.htm. Creating Main
Controller bookshop.do describes how you create this controller.
search.do. This is the controller that is responsible for the book search. It
must react to the searchbutton, process the book data that are entered,
search for suitable books and then write these to an internal table. It then
passes this table to view search.htm. Creating Controller search.do for the
Search describes how you create this controller.
result.do. This controller is responsible for outputting the books that are
found as well as for event handling when a user clicks on a book to display
detailed data about that book. Individual rendering of the author column must
also be determined. Creating Controller result.do for the Results Page
describes how you create this controller.
detail.do. This controller is responsible for determining the detailed data
for a selected book. It then passes this table to view detail.htm. Creating
Controller search.do for the Detail Display describes how you create this
controller.
• Following views
default.htm. This is the main view that consists of the header and 3
HTMLB trays, which contain the search-, result- and detail controllers
and the corresponding views. Creating Main View default.htm describes how
you create this view.
search.htm. Creating View search.htm for the Search describes how you
create the view for inputting the search data.
result.htm. Creating View result.htm for the Results List describes the
view for displaying the results list with an HTMLB table view.
detail.htm. This view returns details on a book selected in the results
table. Creating View detail.htm for the Details Display describes how you
create the view.
about.htm. If no books were found in the search or the results table is
empty for another reason, information about the bookshop should be
displayed instead of the book details. Create the view as described in
Creating View about.htm for the Detail Display.
You can also read the reference documentation on the SAP Web AS
Architecture, which explains the system’s architecture and components:
Features
In this tutorial you will learn how to:
• Use an application class (CL_BSP_TUTORIAL)
• Check user input and write it to the database
• Set cookies on the client side to store information in a stateless application
• Use caching functions
• Use the messages object
• Use the Online Text Repository (OTR)
What’s New?
In this tutorial, the online bookshop that you created in the last tutorial (Online Bookshop) will
be extended to include the following functions and BSPs:
• The page newuser.htm is used to register new customers. New customer data is
stored in the customer table BSCUSTOMER. The page cnewuser.htm shows the
customer that the registration has been successfully completed. For subsequent
orders, the customer simply logs on on the page order.htm using his or her user ID
(e-mail address) and password.
• The page basket.htm is the most important addition. This page displays the current
status of the shopping basket. The user can delete entries and modify the quantity of
an item. If the connection is terminated and then re-opened, the current status of the
shopping basket can be regenerated using a cookie.
• Initally, you will use the application class CL_BSP_TUTORIAL to implement the above
functionality. This class contains the methods for maintaining the shopping basket.
• Caching is used with the results page results.htm.
• Error messages that are output in the case of incorrect user information are
implemented using the messages object. Error pages error.htm and
invalid_isbn.htm, which are available in the third tutorial, are not used as a
result.
• Some of the error messages have been declared as online text repository texts as an
example. OTR texts have the advantage that they are connected to the SAP
translation system.
The ways in which the online bookshop can be extended are described in the section
Extending the Online Bookshop.
The search function and the detailed book data display are transferred from the Online
Bookshop.
The user registration function is also new:
On this page, the customer (user) enters his or her name, address, company, and password.
When the user clicks the done button, the data is checked for completeness and for identical
passwords, and is then entered in the database table BSCUSTOMER.
If the registration is successful, the following page appears:
The next time this user wants to place an order, he or she only needs to enter his or her e-
mail address and password.
Adding an administration function for the shopping basket is another way of further extending
the functionality of the Online Bookshop. When the shopping basket is empty, the page
basket.htm looks like this:
If you search for a book, select it, and place it in the shopping basket, the shopping basket
then looks like this:
On this page, the user can change the number of books, remove items from the basket, and
update the basket.
Once the user has completed the order, he or she chooses Order Basket to place the order.
The following page appears:
On this page, the user enters his or her e-mail and password to authenticate the login. If the
user is not yet a registered customer, he or she can also register on this page.
If the e-mail address and password entered are correct, this activates the order. The page
corder.htm opens.
This completes this addition to the bookshop.
In the next step, you will learn how to trigger the ordering process, for example, by means of a
BAPI. The BAPI in turn triggers the creation of an invoice, the deletion of a book from the
bookshop, and the delivery of an item.
Procedure
Make a copy of the existing BSP application to a new one, with a freely definable name in the
customer namespace. In our example, we used tutorial_4. To do this, go to the Web
Application Builder and open the BSP application tutorial_3. Right-click on the BSP
application and choose Copy.
In the popup that appears, enter ‘tutorial_4’ in the field Target Application.
In the field Target Application, enter the name of your new BSP application.
This page implements the shopping basket function. The user is taken to
this page when he or she places a book in the basket, or modifies the
contents of the basket.
The user is taken to this page when he or she wants to order the current
contents of the shopping basket. At this stage, the user has to authenticate
himself or herself, otherwise the ordering process cannot continue.
This page is used to register new customers. The customers enter their e-
mail address to identify themselves.
This page confirms that a new customer has registered successfully. The
customer’s data is stored in the database table BSCUSTOMER of the
package in question (see Data Model for the Bookshop Tutorials).