Introduction To Web Dynpro For ABAP
Introduction To Web Dynpro For ABAP
Web Dynpro is a new SAP programming model to develop SAP web based applications.
Basic differances between web dynpro ABAP and web dynpro Java
Uses ABAP workbench (SE80) for designing Uses NWDS (Net-weaver Developer Studio) for
web dynpro ABAP applications.
designing web dynpro JAVA applications.
Supports ALV, select-options etc
Portal
Portal is a container of developed internet applications which connects to various heterogeneous servers for
execution .
The best example for portal is www.yahoo.com ,yahoo.com is web portal contains different internet application
like Yahoo News, Yahoo Sports, Yahoo Finance etc, all these applications are individually developed and
integrated into one portal (yahoo.com).
In SAP the web dynpro applications will be developed individually by web dynpro ABAP consultants.
Once the web dynpro application is developed and tested, the application will be integrated into portal
where end users uses these applications.
There are different portal software's available in market ex: web sphere portal, SAP also released it`s own portal
software called Enterprise Portal for integrating SAP applications .
The main advantage of SAP Enterprise Portal is Single Sign On (SSO), SSO is a concept of connecting and
accessing different heterogeneous servers with single username and password.
In Enterprise Portal we integrate different SAP business applications like SD Applications, HR applications, BI
applications(Reports), CRM applications etc which are connected to different servers (SD--R/3 Server, HR--R/3
Server, BI--BI Server, CRM--CRM server etc), by using SSO we can connect to all these applications with single
user name .
Roles and responsibilities of Web Dynpro ABAP consultants and Web dynpro java
consultants
+Web Dynpro is delivered in two programming languages, web dynpro ABAP and web dynpro JAVA.
The below are roles and responsibilities of Web dynpro ABAP and web dynpro JAVA Consultants .
What is MVC architecture in web dynpro ABAP ? Model View Controller in Web Dynpro
ABAP
+Web Dynpro is based on MVC (Model-View-Controller) architecture.
Item
Description
Model
View
Screen/View/page
Controller
Model
Models are objects which contains business logic statements to read or write data into database.The models can
be developed in the form of Function Modules, BAPI`s, Classes etc.
View
View is a screen displayed in browser.
Controller
Controller is an interface between model and the view, it is responsible for taking the input from screen and it
submits to the model, the model will communicate with the database and gives back the result to controller, which
intern submits the result to the screen.
Different types of controllers used in web dynpro for ABAP programming as a part of MVC
architecture
+-
What is a controller ?
Controller is an interface between model and view ( part of MVC architecture), controller is responsible for
communicating view and model.
There are five types of controllers in web dynpro for ABAP.
1. View Controller
A view is nothing but a screen that contain different screen elements like input, table etc
A controller which is responsible for view related logic or programming is called as view controller, a web dynpro
component can have multiple views, each view has it`s own controller.
2. Window controller
A window is a container of views, in web dynpro all views must be inserted into a window to display.
Window controller is a controller which is responsible for window related programming.A web dynpro component
can have multiple windows, each window has it`s own controller.
3.Component Controller
This is a global controller for a web dynpro component, the methods, attributes etc declared in component
controller can be used by all controllers in a component.
4.Interface Controller
Interface controller is a controller which is responsible for communication between two or more web dynpro
components .
5.Custom Controller
This ia an optional controller and this is used to reduce the burden on component controller to improve the
performance.
Custom controllers be also used as a configuration controller and will be used for personalization.
+-
Context
Context is a temporary place where we declare data deceleration's in the form of nodes and attributes.
Attribute
It is used to store a single value, these are similar to fields in table or structure.
Ex: MATNR, MTART, VBELN
Node
Node is a collection of attributes, it is similar to structure or internal table.
Properties of node
Cardinality
It specifies how many records that can be stored in a node, four options are available under cardinality.
Minim
um
Maxim
um
Node can store only one record i:e same as work area.
Node can only be filled through back end logic only ( can not be
used for user input ).
Node can store only one record I:e same as work area
Node can be used for user input .
Node can store 'N' number of records I:e same as internal table
Node can be used for user input .
Description
In web dynpro we create a node for mara with cardinality 0-n or 1-n, both can store 'n' number of records(Internal
table can store n records).In future lesson we will learn when to take 0-n and 1-n cardinality for creating a node.
In ABAP we declare work area like below.
DATA : wa_MARA TYPE MARA.
In web dynpro we create a node for mara with cardinality 0-1 or 1-1, both can store one record only(work area
can store only one record).In future lessons we will learn when to take 0-1 and 1-1 cardinality .
Creating a node in webdynpro for ABAP, nodes and attributes in web dynpro for ABAP
programming.
+Node : Node is nothing but a collection of attributes, node can be used as internal table or work area based on
the selected cardinality .
Nodes can be created in view controller, component controller and window controller .
Save it in a local object, expand views and double click on main view.
Now node is created with mara structure( work area for MARA table because cardinality is 1-1, it can store only
one record).
We will discuss more details in future lessons.
Creating UI elements in webdynpro for ABAP, UI element properties in SAP web dynpro
+UI Element : UI elements are screen elements which are used to design screen in web dynpro ABAP, each UI
element has some specific properties .Properties of UI elements:There are three kinds of properties for UI
elements.
1.
Mandatory.
2.
Can be bindable.
3.
Not bindable.
We will discuss about all properties of UI elements in future lessons, in this lesson we will be learning how to
create UI elements.
Go to SE80, select Web Dynpro Comp./Intf. from drop down, provide a web dynpro component name and press
enter.
Save it in a local object, expand views and double click on main view.
A popup will open, provide ID, select type from drop down, enter.
Now the UI element is inserted, we will learn designing layout with UI elements in next lessons.
Data binding in web dynpro for ABAP, binding UI elements to nodes and attributes
+
Binding the UI element data { ex: Input field, check box, table etc } to corresponding node or attribute is
called data binding.
.By using the data binding concept we can control multiple properties of a UI element like visibility,
enable/disable etc.
The UI element properties can be manipulated through context by using data binding.
Select PageHeader, and provide title in the properties area and enter.
Save (Ctrl S), double click on component name (ZSAPN_HELLO_WORLD), right click and aativate.
Application is created, right click on application name (not component name) and test.
Step1: Go to transaction SE80, select web dynpro component from drop down, provide name as
ZSAPN_CUSTOMER_DETAILS, enter, click yes, provide description, enter and save it in a local object.
Step2: Go to main view, go to context, right click on context -> Create -> node, provide name as KNA1, provide
dictionary structure as KNA1, cardinality 1-1, selection 0-1 and click on add attributes from structure.
Step3: A popup will come, select KUNNR, NAME1, ORT01 and LAND1 and press enter.
Step4: Select node and remove dictionary structure under node properties.
Step5: Go to layout tab, right click on rootuielementcontainer, create container from, click on context and select
KNA1, enter.
Step6: Again right click on rootuielementcontainer -> insert element , provide id as BTN_GET and type as
BUTTON, press enter.
Step7: Provide button text as get customer and create an action method on_get.
Step8:Go to actions tab, double click on on_get.
1. Read node static attributes using code wizard.
2.Get data from KNA1 and set data to node using set_static_attributes method.
Step8:Save and activate the component.
Step9:Test the application.
Provide a customer number(get from KNA1 table) and clcik on get customer, it will fill all fields.
Working with table UI element in SAP web dynpro ABAP programming, table UI element
properties
+Requirement : Develop a web dynpro component to display list of vendors .
UI elements to be used in this requirement are INPUT FIELD,LABEL, BUTTON and TABLE .
Go to context of main view, click on change mode, right click on context -> create -> node.
A popup will open, provide node name as LFA1, data dictionary structure as LFA1, click on add attributes from
structure button.
Step2: Go to layout and insert table UI element.Go to view layout, right click on ROOTUIELEMENTCONTAINER,
insert element, provide a id and select table, enter.
Step3:Create data binding for table.Right click on table, click on create binding, click on context.
Select LFA1.
Step4: Add logic to get data.Go to METHODS tab, double click on WDDOINIT add below code.
DATA LO_ND_LFA1 TYPE REF TO IF_WD_CONTEXT_NODE.
* IF lo_nd_lfa1 IS INITIAL.
* ENDIF.
working with check box UI element in web dynpro for ABAP, web dynpro ABAP check box UI
element
+Create and design component as per below diagram.
Step1: Go to SE80, create a web dynpro component ZSAN_CHECKBOX, save it in a local object.
Step2: Double click on main view, click on change, go to context, create a node CHK with (1 1) cardinality and create two attributes as below.
CHK -> TYPE -> CHAR1.
SELECTED -> TYPE -> CHAR30.
Step3: Go to layout, right click on ROOTUIELEMENTCONTAINER, insert element id : CHK, type : Checkbox,
enter, create binding for the property VALUE to CHK of node CHK, create an action method
ON_CHK_SEL for ON_TOGGLE of CHK. Similarly insert another UI element
id: TEXT, type: TextView, enter, create data binding for the property text to SELECTED of node
CHK.
Step4: Go methods, double click on WDDOINIT, and add below logic.
Step5: Save and activate whole component, create application and test.
Working with radio button group in web dynpro for ABAP, using radio button group UI
element
+As a part of real-time projects, we don`t use individual radio buttons, instead we use radio button group UI
element, Radio Button Group Ui element is a UI element which created multiple radio buttons in the form of a
group.
SAP has provided two options for this radio buttons groups in web dynpro ABAP, based on the requirement we
can choose suitable one.
This is used when ever we have fixed values for a domain ex: Gender (go to SE11, select domain,
provide GENDER, display to check fixed values).
This is used when ever we have dynamic number of radio buttons with dynamic values.
The number of radio buttons are determined dynamically ex: radio buttons for material type (we will
discuss in next lessons)
Working with radio button group by key UI element in SAP web dynpro ABAP
+-
Radio Button Group by Key: When ever we have fixed values for a domain, we will use this UI element to
display them in the form of radio button group.
In the below example we are going to display GENDER, in the form of radio button by using radio button
by key UI element.I recommend you to check GENDER domain in SE11 and understand fixed values.
Select RBG UI element, click on the yellow icon under properties, select GENDER attribute.
Go to view context, create one more attribute with name text, type char30.
Go to layout, create one more UI element TextView UI element, bind text property to TEXT attribute.
* IF lo_nd_rbg IS INITIAL.
* ENDIF.
LO_EL_RBG = LO_ND_RBG->GET_ELEMENT( ).
* @TODO handle not set lead selection
IF LO_EL_RBG IS INITIAL.
ENDIF.
LO_EL_RBG->GET_STATIC_ATTRIBUTES(
IMPORTING
STATIC_ATTRIBUTES = LS_RBG ).
IF LO_EL_CONTEXT IS INITIAL.
ENDIF.
lv_text = 1.
IF LS_RBG-GENDER = 'F'.
ENDIF.
VALUE = LV_TEXT ).
+-
RadioButtonByIndex: It is a Ui element, which creates radio button group with dynamic number of radio
buttons.
Go to main view, go to context , create a node RBG_INDEX with cardinality (0 - n), create two attributes
MTART ->TYPE-> MARA-MATRT, TEXT -> TYPE -> CHAR30.
Step3:Design Layout.
Create another UI element TextView, bind text property to attribute SELECTED of node RBG_INDEX.
* IF lo_nd_RBG_INDEX IS INITIAL.
* ENDIF.
CLEAR LS_RBG_INDEX.
CLEAR LS_RBG_INDEX.
CLEAR LS_RBG_INDEX.
CLEAR LS_RBG_INDEX.
* IF lo_nd_RBG_INDEX IS INITIAL.
* ENDIF.
IF LO_EL_RBG_INDEX IS INITIAL.
ENDIF.
IF LO_EL_CONTEXT IS INITIAL.
ENDIF.
* lv_seletext = 1.
NAME = `SELETEXT`
VALUE = LV_SELETEXT ).
Working with drop downs in SAP Web Dynpro for ABAP to display drop down lists
+Just like Radio Button Group, drop down also have two kinds of development options.
1.
2.
Just like Radio Button Group, drop down also have two kinds of development options.
Working with Drop Down by Key in Web Dynpro for ABAP to display drop down list using
domain fixed values.
+-
A popup will come provide some description and enter, save in a local object.
Step2: Double click on main menu, click on change, go to context tab, right click on context, create->node.
Step3: Right click on node DDK, create->attribute, provide name as GENDER -> TYPE -> GENDER and enter.
A popup will come, provide id: DDK, type: DropDownByKey and enter.
Similarly right click on ROOTUIELEMENTCONTAINER, insert element id: Test, type: TextView and enter.
Step5: Go to actions tab, double click on ON_SELECT method and add below code.
working with Drop Down by index UI element in web dynpro for ABAP
+Create and design component as per below diagram.
Step1: Go to SE80, create a web dynpro component ZSAN_DD_INDEX, save it in a local object.
Step2: Double click on main view, click on change, go to context, create a node DD_INDEX with (0 - n) cardinality
and create two attributes as below.
MTART -> TYPE -> MARA_MTART.
SELECTED -> TYPE -> CHAR30.
Step3: Go to layout, right click on ROOTUIELEMENTCONTAINER, insert element id : DDI, type :
DropDownByIndex, enter, create binding for the property texts to MTART of node DD_INDEX.
Similarly insert another UI element id: TEXT, type: TextView, enter, create data binding for the property
text to SELECTED of node DD_INDEX.
Step4: Go methods, double click on WDDOINIT, and add below logic.
Step5: Save and activate whole component, create application and test.
WDDOINIT:
Method for initialization logic, this is the first method displayed before view is displayed. This method is used to
initialize variables, default data etc.
WDMODIFYVIEW:
This method is used to modify view dynamically based on user actions, this is used for dynamic programming.
WDDOBEFOREACTION:
This method is used to validate user input.
WDDOAFTERACTION:
Method for all common logic used in all methods or event handler methods.
WDEXIT:
This method is used for clearing/refreshing nodes, attributes etc.
Using WDDOINIT method in web dynpro ABAP, initialization in web dynpro for ABAP
+WDDOINT is the hook method which will trigger first and it will be triggered before displaying the view, so we can
use this method to initialize data(input fields, display data etc), it is like initialization event in SAP ABAP.
Previously we have used this method so many times, in different demo components. check for example: Using
table UI element in web dynpro ABAP etc.
Webdynpro Programming
web dynpro programming for reading nodes, attributes without using code wizard
+Most of the times we use code wizard to read a node or attribute, but is very important for us to write code
manually or reading a node or attribute or table, by the end of this lesson you will be able to understand manual
code writing.
IF LO_EL_NODE_NAME IS INITIAL.
ENDIF.
Step2:Create an instance for the node using root node instance and by using method get_child_node .
CALL METHOD WD_CONTEXT->GET_CHILD_NIDE(
EXPORTING
NAME = '<NODE_NAME>'
IMPORTING
INSTANCE = <NODE> ).
Step3: Get element instance using node instance and method get_element.
CALL METHOD <NODE>->GET_ELEMENT(
*EXPORTING
* INDEX = <INDEX> "by default lead selection
RETURNING
INSTANCE = <ELEMENT>).
Step4: Now read node or attribute into work area or internal table using node and element instance.
To read a single attribute .
CALL METHOD <ELEMENT>->GET_ATTRIBUTE(
EXPORTING
NAME = <ATTRIBUTE_NAME> ex: MATNR in MARA node
IMPORTING
VALUE = <LV_VAL>).
Most commonly used methods in web dynpro ABAP for context operations
+The below are the methods we use most commonly in web dynpro component development.
Reading
Writing
1. Group Container
Using group container, we can embed other UI elements into it with a title (caption), borders and colors. We can
specify height and width to it.
2. Transparent Container
This container is a plain container, which doesnt have borders, colors and caption.
3. TRAY
It is a container with expandable and collapsible options, by using TRAY we can get caption, borders but no
colors.
Working with container UI elements in web dynpro ABAP, container UI elements in web
dynpro ABAP
+-
Group container is an UI element, we can insert other UI elements into it, using this we can format design of a
web dynpro screen(view).
Step1: Go to SE80, create a web dynpro component ZSAPN_GROUP_CONTAINER.
Step2: Go to Main view, go to layout, right click on rootuielementcontainer ->insert element, provide id as G1,
type as group.
Step3: Group is inserted, by default caption will be created for group, select CAPTION, provide text under
properties.
Step4: Now you can insert other UI elements into it.
Working with transparent container in web dynpro for ABAP, transparent container web
dynpro ABAP
+Transparent container is an UI element, we can insert other UI elements into it, using this we can format design of
a web dynpro screen(view).
Step1: Go to SE80, create a web dynpro component ZSAPN_TRANSPARENT_CONTAINER.
Step2: Go to Main view, go to layout, right click on rootuielementcontainer ->insert element, provide id as T1, type
as 'TransparentContainer'.
Step3: Transparent container is inserted.
Step4: Now you can insert other UI elements into it.
Working with tray container in web dynpro ABAP, tray container in web dynpro abap
+TRAY container is an UI element, we can insert other UI elements into it, using this we can format design of a
web dynpro screen(view).
Step1: Go to SE80, create a web dynpro component ZSAPN_TRAY_CONTAINER.
Step2: Go to Main view, go to layout, right click on rootuielementcontainer ->insert element, provide id as TR1,
type as 'Tray'.
Step3: Group is inserted, by default caption will be created for group, select CAPTION, provide text under
properties, we can set borders for this.
Step4: Now you can insert other UI elements into it.
Flow Layout
This layout arranges all the UI elements sequentially in a single line form left to right.This ts the default layout in
web dynpro ABAP.
Row layout
This layout arranges the UI elements in a same line or separate line, this layout have two options.
1.
2.
Matrix Layout
This layout is same as row layout, by using this we can arrange UI elements in same line or separate line with
vertical formatting options.
Matrix layout have two options
1.
2.
Grid Layout
This layout arranges the UI elements with the help of column count, we can display UI elements as columns.By
using grid layout we can specify column spacing, column count(UI elements ti display in specific columns),
padding etc.
This layout arranges all the UI elements sequentially in a single line from left to right, this is a default layout.
Click on context.
Provide an ID, select button from drop down and press enter.
Select button, provide a button text and click on create to create an action method.
METHOD ONACTIONON_GET .
DATA LO_ND_KNA1 TYPE REF TO IF_WD_CONTEXT_NODE.
DATA LO_EL_KNA1 TYPE REF TO IF_WD_CONTEXT_ELEMENT.
DATA LS_KNA1 TYPE WD_THIS->ELEMENT_KNA1.
* navigate from to via lead selection
LO_ND_KNA1 = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_KNA1 ).
* get element via lead selection LO_EL_KNA1 = LO_ND_KNA1->GET_ELEMENT( ).
* @TODO handle not set lead selection
IF LO_EL_KNA1 IS INITIAL.
ENDIF.
* get all declared attributes
LO_EL_KNA1->GET_STATIC_ATTRIBUTES(
IMPORTING
STATIC_ATTRIBUTES = LS_KNA1 ).
SELECT SINGLE * FROM KNA1 INTO CORRESPONDING FIELDS OF LS_KNA1
WHERE KUNNR = LS_KNA1-KUNNR.
LO_EL_KNA1->SET_STATIC_ATTRIBUTES(
EXPORTING
STATIC_ATTRIBUTES = LS_KNA1 ).
ENDMETHOD.
Provide name, enter, click save (Ctrl + S) and save it in a local object.
Right click on application name and click test to test the application.
A browser will open, provide a customer no(get from KNA1 table) and click on get.
Working with row layout in web dynpro ABAP, UI element allignment using row layout
+Step1: Go to Se80, create a web dynpro component ZSAPN_ROW_LAYOUT.
Step2: Expand view, double click on main view, click change.
Step3: Go to context right click on context -> create -> node, provide name as KNA1, dictionary structure as
KNA1, cardinality 1-1 and click on add attributes from structure. Select KUNNR, NAME1, LAND1 and ORT01,
press enter.
Step4: Select node KNA1 and remove dictionary structure.
Step5: Go to layout, right click on rootuielementcontainer -> create container form, click on context, select KNA1,
select row layout and press enter.
Step6: Select input field, select layout data from drop down and try changing and observe changes.
Working with matrix layout in web dynpro for ABAP, align screen elements using matrix
layout
+Step1: Go to Se80, create a web dynpro component ZSAPN_ROW_LAYOUT.
Step2: Expand view, double click on main view, click change.
Step3: Go to context right click on context -> create -> node, provide name as KNA1, dictionary structure as
KNA1, cardinality 1-1 and click on add attributes from structure. Select KUNNR, NAME1, LAND1 and ORT01,
press enter.
Step4: Select node KNA1 and remove dictionary structure.
Step5: Go to layout, right click on rootuielementcontainer -> create container form, click on context, select KNA1,
select matrix layout and press enter.
Step6: Select input field, select layout data from drop down and try changing and observe changes.
Working with grid layout in web dynpro for ABAP, alignment of screen elements using grid
layout
+Grid layout is the most commonly used layout in web dynpro ABAP, because it has very good options to arrange
screen elements (UI elements), by using grid layout we can specify column count, padding etc.
Step1: Go to transaction SE80, create a web dynpro component ZSAPN_GRID_LAYOUT and save it in a local
object.
Step2: Go to main view, go to context create a node KNA1 with four attributes.
Step3: Insert a group container, go to layout, right click on rootuielementcontainer -> insert element, provide id as
G1, type as 'Group' and enter.
Step4: Right click on group G1 -> create container form, click on context, select KNA1, select 'GridLayout' and
enter.
Step5: Select group, scroll down and you can specify options for column count, cell spacing and cell padding.
2.
If we need to display a view, it must be embedded into a window, without a window we cannot display
view.
Outbound Plugs
Inbound Plugs
Step7: Expand window, drag and drop MAIN, SECOND view into window.
Step8: Expand two views, right click on GOTO_SECOND -> Create Navigation Link, press F4, select destination
view as SECOND and enter.
Step9: Right click on GOTO_MAIN -> Create Navigation Link, press F4, select destination view as MAIN and
enter.
Step10: Go to main view actions tab, double click on ON_NEXT method and add below code. wd_this>FIRE_GOTO_SECOND_PLG( );
Step11: Go to SECOND view actions tab, double click on ON_PREVIOUS method and add below code. wd_this>FIRE_GOTO_MAIN_PLG( );
Step12: Save and activate the component.
Step13: Test the component.
Working with view plugs in web dynpro ABAP, simple example on view plugs and view
navigation in web dynpro ABAP
+The below is the simple example of using view plugs in web dynpro for ABAP, hope you understand the concept
of plugs in web dynpro abap
A popup will come, provide id as BT1 and type as button and enter.
Select button ui element, provide text, create action method under events, a popup will code, provide action and
description and enter.
Select button, provide text, click on create under events, provide action and description and enter.
Repeat the same steps in SECOND view by adding plug names as IN_SECOND (inbound plug) and
GOTO_MAIN (outbound plug).
Navigation link is a link between outbound and inbound plug, through which an outbound plug will identify the
destination(target view).
Expand main view and right click on outbound plug -> create navigation link .
Similarly create navigation link for outbound plug of second view right click on GOTO_MAIN -> create navigation
link, popup opens press F4, select MAIN and enter.
WD_THIS->FIRE_GOTO_SECOND_PLG(
).
Similarly go to SECOND view, actions, double click on ON_BT2 method and fire outbound plug (GOTO_MAIN).
below code will be generated.
WD_THIS->FIRE_GOTO_MAIN_PLG(
).