You are on page 1of 13

Service call in WebDynpro application

By Somu shekar, Microexcel

Whats the use of service call?


Using service call we can get the data from data base using a remote enabled function module and show
in the internet browser using a webdynpro application.
Steps for creating a webdynpro application using service call.
Step 1
Create a custom table in the data base with the required fields.

Step 2
Create a Remote Enabled Function module and write the code to get the data from the custom table
created.

Step 3
Create a Webdynpro component with a window and a view

Step 4
Right click on the component and create a Service call as follows.

Just click on continue

Select the Use existent Controller radio button and give the component controller name in the box
provided and click on continue.

Select the service type as function module and click on continue.

Give the function module name created in step 2 and click on continue.

Click here to continue...


...Previous

Click on the check box itab for the internal table name and continue

Give the method name and some description and continue

Click on complete to complete the service call.

In the component controller context the node itab is created with the desired fields.

Step 5
Just drag and drop node itab to the view context.

Step 6
Insert a table element in the view layout and bind it with the node itab.

Step 7
Insert a button element and in the on action method call the executemd method given in the step 4 .
Code is :
wd_Comp_Controller->Executemd( ).
It calls the Executemd method of the component controller and populates the data into the table
Step 8
In the second view insert three input elements and bind them with respective fields of itab, also insert two
buttons for update and back actions.

Step 9
Copy the code in the update action method implementation.
data
data
data

lo_window_manager
lo_api_component
lo_window

:
:

lo_api_component
lo_window_manager
data
ls_string
ls_string
insert

:
=

=
lt_string
like
'do
you
ls_string

CALL

to
ref
ref

type
line
want

to
to

if_wd_window_manager.
if_wd_component.
if_wd_window.

table

of
of

to

update

into

CALL
METHOD
EXPORTING
TEXT
BUTTON_KIND
RECEIVING
RESULT
.
data:
l_Api_Secondview
type

the
table

data

).
).
string,
lt_string.
base'.
lt_string.

LO_WINDOW_MANAGER->CREATE_POPUP_TO_CONFIRM
=

lt_string
4

=
=
ref
=

lo_window->open(

ref

wd_comp_controller->wd_get_api(
lo_api_component->get_window_manager(

l_Api_Secondview

type
type
type

lo_window.
to

IF_WD_VIEW_CONTROLLER.

wd_This->Wd_Get_Api(

).
).

METHOD

LO_WINDOW->SUBSCRIBE_TO_BUTTON_EVENT

EXPORTING
BUTTON
=
ACTION_NAME
ACTION_VIEW
=
CALL
METHOD
EXPORTING
BUTTON
=
ACTION_NAME
ACTION_VIEW = l_api_secondview .

if_wd_window=>co_button_yes
'YES'
l_api_secondview
.
LO_WINDOW->SUBSCRIBE_TO_BUTTON_EVENT
=

if_wd_window=>co_button_no
'NO'

Click here to continue...


...Previous

Step 10
Method SUBSCRIBE_TO_BUTTON_EVENT creates a popup with yes or no buttons. If yes button is
pressed the data base is updated successfully and if pressed NO, no action should happen. For this we
need to create an action YES and NO in the actions tab.

In the methods tab two method handlers will be created where we can write required logic.

Step 11
Copy the following code in the ONACTIONYES method implementation.
data:
l_current_controller
l_message_manager
type
l_current_controller

type
ref
?=

ref

to
to

if_wd_controller,
if_wd_message_manager.

wd_This->Wd_Get_Api(

).

CALL
METHOD
l_current_controller->GET_MESSAGE_MANAGER
RECEIVING
MESSAGE_MANAGER
=
l_message_manager
.
data:
Node_Itab
type
ref
to
If_Wd_Context_Node,
Elem_Itab
type
ref
to
If_Wd_Context_Element,
Stru_Itab
type
If_Secondview=>Element_Itab
.
data
:
ls_itab
type
zstudent.
*
navigate
from
<CONTEXT>
to
<ITAB>
via
lead
selection
Node_Itab
=
wd_Context->get_Child_Node(
Name
=
`ITAB`
).
*
Elem_Itab

get

element

via
lead
Node_Itab->get_Element(

*
get
all
Elem_Itab->get_Static_Attributes(
importing
Static_Attributes
=
ls_itab-empno
ls_itab-ename
ls_itab-esal
modify
zstudent

declared
Stru_Itab
=
=
=
from

selection
).
attributes
).
Stru_Itab-empno.
Stru_Itab-ename.
Stru_Itab-esal.
ls_itab.

if
*
CALL
EXPORTING
MESSAGE_TEXT
endif.

sy-subrc

eq

report
METHOD
=

'

0.
message
l_message_manager->REPORT_SUCCESS
Updated

successfully'.

Step 12
Create an application for the component and test it. Click on get data to get the data from data base

Click on next to go to next screen where it displays the user selected line

Change the data if needed and click on update.

On the popup screen, click on Yes to update the data base or click on No to do nothing. After updating a
confirmation message will be displayed.

You might also like