Beruflich Dokumente
Kultur Dokumente
ABAP Course
Chapter 9: Web Dynpro
Content
This chapter explains the main
concepts of Web Dynpros. The MVC
concept is applied throughout the
exercise.
Prerequisites
You should be familiar with ABAP, the
MVC concept and navigation in the
SAP system.
Motivation
This chapter explains how to create a
simple
Web Dynpro application.
Furthermore it shows how to set up
navigation between different Web
Dynpro views.
Lecture notes
A fundamental understanding of
programming language ABAP and the
SAP development environment is a
prerequisite for the students.
Product: All
Level: Beginner
Focus: Programming
Version: 1.0
Page 1
CHAPTER 9
Task 1: Login into the SAP system
Short description: Use SAP Gui to login into the SAP system with your username
and password
Login
Start the SAP Gui and login into the development system using the provided
account and password. Please refer to chapter 1 for your username and your
password.
Task 2: Creating a Web Dynpro application
Short description: In this exercise you will create a Web Dynpro application that
shows flight information. You can search for flights by carrier, and all flights found
will be shown in a table. You are going to use a BAPI to access the flight
information.
Please start the Object Navigator from the SAP Easy Access Menu by using the
following path:
Menu path
You may also use the transaction code SE80 for direct access.
object tree and open the context menu to create a new view. Create a
view using MAIN as technical name. The Layout tab and the View Designer can
be accessed by clicking on the Button
. Save the view MAIN.
After saving the view, it is displayed in the object tree of the Web Dynpro
component under the entry Views.
Service Call You will use the function module BAPI_FLIGHT_GETLIST to access
the flight data. Therefore you will create a Service Call to call the
function module. To create a service call, you can use the wizard
within the Web Dynpro tools in the ABAP Workbench. At first, position
the cursor on the top node of the Web Dynpro component ZY_##_FLIGHT_APP.
Use the context menu to choose the entry Create and then the entry Service Call.
Press Continue.
Page 2
CHAPTER 9
In the following dialogue, you can choose whether the existing controller will be
used or whether a new controller is to be created for this purpose. As you are going
to use the existing component controller to call the function module, check the
radio button Use Existent Controller and enter COMPONENTCONTROLLER as
Controller.
Press Continue.
Select the radio button Function Module to determine the service type.
Press Continue.
Enter the Function Module BAPI_FLIGHT_GETLIST.
Press Continue.
Adapt the suggested context information as following: Change the ObjectType for
Parameter Airline and Flight_List to the value Context (Node/Attribute).
Press Continue.
Now you can specify the method name. You can use the suggested default values,
that should be as following:
Component:
Controller:
Method:
ZY_##_ FLIGHT_APP
COMPONENTCONTROLLER
EXCUTE_BAPI_FLIGHT_GETLIST*
Press Continue and Complete. The component controller context now displays
the corresponding context nodes used in the function module call. Furthermore, the
controller method EXECUTE_BAPI_FLIGHT_GETLIST is now existent. Switch to
the Methods tab of the component controller and display the source code of the
controller method EXECUTE_BAPI_FLIGHT_GETLIST. The method reads flight
data for a specified Airline and assigns the resulting table to the context node
FLIGHT_LIST.
Save your changes using the Save
Button
Context Mapping In a next step, you define the context mapping from the global
Page 3
CHAPTER 9
A pop-up window will ask you if you want to copy and map the selected node.
Press Yes for each node. Now you have finished the context mapping. Save your
changes.
Group In a next step, you define one input field Airline and one Search button in
the view. Switch to the Layout tab of the view MAIN. Insert a new group
element into the ROOTELEMENTCONTAINER named GROUP_1 using the
context menu. In the properties windows, enter a width of 100% for
GROUP_1 and enter Search flights as Caption text.
Container Form Create a new Container Form in the context menu of GROUP_1.
In the window displayed, choose Input field as Standard Cell
Editor. Click on the Context button and double click on the
context node IMPORTING. Press ENTER.
Page 4
CHAPTER 9
Now
the
event
handler
for
the
action
SEARCH_FLIGHTS
(ONACTIONSEARCH_FLIGHTS) needs to be modified. Double click on the action
SEARCH_FLIGHTS in the properties window of BUTTON_SEARCH. You are now
directed to the generated event handler method ONACTIONSEARCH_FLIGHTS.
A call to the controller method EXECUTE_BAPI_FLIGHT_GETLIST has to be
inserted into this method. Therefore, click on the Web Dynpro Code Wizard
and choose the option Method Call in Used Controller. Select the component
Name
ZY_##_FLIGHT_APP
and
the
controller
method
EXECUTE_BAPI_FLIGHT_GETLIST.
Select Continue.
Page 5
CHAPTER 9
The generated coding should look as following:
method ONACTIONSEARCH_FLIGHTS .
DATA lo_componentcontroller TYPE REF TO ig_componentcontroller .
lo_componentcontroller =
wd_this->get_componentcontroller_ctr( ).
lo_componentcontroller->execute_bapi_flight_getlist( ).
endmethod.
Table Now switch to the Layout tab of the view and create a table
TABLE_FLIGHTS.
Therefore
click
right
on
the
ROUTUIELEMENTCONTAINER and chose Insert element. Enter the
TABLE_FLIGHTS and chose the type table. Set Flights as caption text and a
width of 100%.
Create the data binding between the element TABLE_FLIGHTS and the context
node FLIGHT_LIST by using the Create Binding option in the tables context
menu.
Click on the Context button and double click on the context node FLIGHT_LIST.
Activate binding for all context attributes. Press Continue and save all changes.
Embedd view into window Now the view MAIN needs to be embedded into
Button.
Page 6
CHAPTER 9
Page 7
CHAPTER 9
Enter ADDITIONAL_INFO as node name. Select 0..1 for the cardinality in the
properties of the node. The structure BAPISFLADD is the assigned dictionary
structure. Enter a supply function with the name get_add_info. Then click on Add
Attribute from Structure.
Page 8
CHAPTER 9
Select all fields and press continue. The new node ADDITIONAL_INFO should be
displayed as a sub node of the node FLIGHT_LIST and contain the selected
attributes. Double click on the supply function GET_ADD_INFO in the properties
panel. During runtime, the node ADDITIONAL_INFO will be filled with additional
flight data dependent on the parent nodes lead selection. The lead selection is
represented by the specific flight selected in the table of view MAIN.
The method GET_ADD_INFO therefore first has to determine the current data of
the parent node, that can be retrieved via the parent_element object. For retrieving
the additional information about a selected flight, the function module
BAPI_FLIGHT_GETDETAIL is used. Enter the following coding for method
GET_ADD_INFO:
method get_add_info .
data ls_parent_attributes type wd_this->element_flight_list.
parent_element->get_static_attributes(
importing
static_attributes = ls_parent_attributes ).
** data declaration
data ls_additional_info type wd_this->element_additional_info.
** service call
call function 'BAPI_FLIGHT_GETDETAIL'
exporting
airlineid
= ls_parent_attributes-airlineid
connectionid
= ls_parent_attributes-connectid
flightdate
= ls_parent_attributes-flightdate
importing
additional_info
= ls_additional_info.
.
** bind a single element
node->bind_structure(
new_item
= ls_additional_info
set_initial_elements = abap_true ).
endmethod.
Now open the context tab of view ADD_INFO. Navigate to the context node
ADDITIONAL_INFO of the component controller context and drag and drop it to the
local context of view ADD_INFO.
In the tab Layout of view ADD_INFO add a new group GROUP_2. In the
properties window, select GridLayout as Layout. Assign Additional Information
as Caption text.
Now add a Container Form to GROUP_2. Select ADDITIONAL_INFO as context
node and Input Field as Standard Cell Editor. Press continue.
Finally, add a Button to GROUP_2. Name the button BUTTON_BACK and enter
Back to search as text in the properties window.
Now you have to setup the navigation between the view, using inbound and
outbound plugs. Create an inbound plug DISPLAY_ADD_INFO on the Inbound
Plugs tab of view ADD_INFO. Furthermore, create an outbound plug
BACK_TO_SEARCH on the Outbound Plugs tab of view ADD_INFO.
Now go to the layout tab of view ADD_INFO and select the Button
BUTTON_BACK. In the properties window, create an new action BACK for even
onAction. Enter BACK_TO_SEARCH as Outbound Plug.
Page 9
CHAPTER 9
Page
CHAPTER 9
Page