SlideShare uma empresa Scribd logo
1 de 24
Baixar para ler offline
1
Dynamic
Modifications
at Runtime
2
© SAP AG 2005, ABAP Web Dynpro
Introduction
Modifying the context structure at runtime
Modifying the UI Element hierarchy at runtime
The use of dynamic actions
Contents:
Dynamic Modifications at Runtime
3
© SAP AG 2005, ABAP Web Dynpro
Dynamic Modifications at Runtime: Objectives
After completing this lesson, you will be able to:
Understand what dynamic programming is
Dynamically modify and create UI elements
Dynamically create context elements
Dynamically bind UI element values to context
elements
Dynamically create actions
4
Dynamic Runtime Modifications
Up till now, we have looked exclusively at the declarative approach to Web Dynpro
programming. Now, we will turn our attention to the programmatic techniques
needed to perform programmatically, the steps that have so far, only been done
declaratively.
© SAP AG 2005, ABAP Web Dynpro
Dynamic Runtime Modifications
What is type of dynamic modifications can be made at
runtime?
Dynamic Context Manipulation
The creation, modification and deletion of context nodes and
attributes
Dynamic UI Manipulation
The creation, modification and deletion of UI elements
Dynamic Assignment of Actions to UI Elements
5
Dynamic Runtime Modifications
Usually, you would declare the structure of a controller’s context at design time,
and then create a static UI layout to display the data contained within the declared
context.
However, it is perfectly possible to create a context and UI layout hierarchy at
runtime. These techniques should only be used when they are required!
It is preferable to create as much of your context and UI layout hierarchy as
possible at design time.
© SAP AG 2005, ABAP Web Dynpro
Dynamic Runtime Modifications
There are several situations in which type of coding could be
required:
When the structure of your data is not known until runtime
When you want the behaviour of a screen to be generic – and
therefore dynamic
When you are writing utility components that must function in
a generic manner
Etc…
Under what circumstances should I write coding that
performs dynamic modifications?
6
WDDOMODIFYVIEW
This Standard Hook method is called just before the view layout is rendered. It is
the only method in which the programmer is allowed direct access to the UI
element objects themselves.
The FIRSTTIME parameter is a boolean value that lets you know if the screen is
being rendered for the very first time, or re-rendered in response to an Action
event.
© SAP AG 2005, ABAP Web Dynpro
Standard Hook Method – View controller
Only a view controller has these hook methods.
The method WDDOMODIFYVIEW will only be called if:
The view is part of the current view assembly and this is the
first time the view is required, or
The view is part of the current view assembly and an action
belonging to the same view controller has been processed.
7
© SAP AG 2005, ABAP Web Dynpro
Dynamic Context Data Creation
Example of context
metadata to be created
dynamically?Context Root (c=1..1, s=true)
FLIGHTS (c=0..n, s=true)
Context Metadata to be
created at runtime
BOOKINGS (c=0..n, s=false)
PRICE
CARRID
CONNID
FLDATE
BOOKID
CUSTOMID
CLASS
PASSNAME
8
Context node creation
All context nodes created by the application developer must have some other
node acting as their parent. This is why a context is always supplied containing a
root node. The root node is the anchor point for all other nodes, irrespective of
whether they created statically at design time, or dynamically at runtime.
Node creation principle
1.Create the node’s metadata
2.Create the node instance based on the new metadata
© SAP AG 2005, ABAP Web Dynpro
Coding steps:
Obtain a reference to the metadata of
the context node that will act as the new
node’s parent. In this case, we are
creating an independent node, therefore
we get a reference to the metadata of
the root node.
Call static method
create_nodeinfo_from_struct( ) from
helper class cl_wd_dynamic_tool
A DDIC Structure can be used for the
attribute creation.
Dynamic Value Node Creation (1)
Context Root (c=1..1, s=true)
FLIGHTS (c=0..n, s=true)
Context Metadata to be
created at runtime
BOOKINGS (c=0..n, s=false)
PRICE
CARRID
CONNID
FLDATE
BOOKID
CUSTOMID
CLASS
PASSNAME
DDIC Structure SFLIGHT
9
Creating an value node
We are now dealing with the structure of the context not the contents, therefore we
must work with the metadata that describes the context nodes and attributes,
rather than the runtime data contained within node collections. This means we will
be working with if_wd_context_node_info objects.
1.Get a reference to the metadata of the node acting as the parent of the new node.
2.Use method create_nodeinfo_from_struct from helper class cl_wd_dynamic_tool to create a
node from a structure.
© SAP AG 2005, ABAP Web Dynpro
Dynamic Node Creation related to a structure
Coding steps:
Obtain a reference to the metadata of the context node that will act as the
new node’s parent.
Call static method create_nodeinfo_from_struct( ) from helper class
cl_wd_dynamic_tool to create from a DDIC structure a node.
DATA: rootnode_info TYPE REF TO if_wd_context_node_info,
table_name type string value 'SFLIGHT',
node_name type string value 'CONNECTIONS'.
* get root node info of context
rootnode_info = wd_context->get_node_info( ).
* create node named CONNECTIONS of sflight
cl_wd_dynamic_tool=>create_nodeinfo_from_struct(
parent_info = rootnode_info
node_name = node_name
structure_name = table_name
is_multiple = abap_false
is_mandatory = abap_true ).
Cardinality 1…1
10
© SAP AG 2005, ABAP Web Dynpro
Dynamic Sub Node Creation related to a structure
DATA: dyn_node type ref to if_wd_context_node,
dyn_node_info TYPE REF TO if_wd_context_node_info,
. . .
* navigate from <CONTEXT> to <UI_ATTRIBUTES> via lead selection
dyn_node = wd_Context->get_Child_Node( Name = node_name ).
dyn_node_info = dyn_node->get_node_info( ).
* create sub node named BOOKINGS of sbook
cl_wd_dynamic_tool=>create_nodeinfo_from_struct(
parent_info = dyn_node_info
node_name = 'BOOKINGS'
structure_name = 'SBOOK'
is_multiple = abap_false
is_mandatory = abap_true ).
Context Root (c=1..1, s=true)
FLIGHTS (c=0..n, s=true)
BOOKINGS (c=0..n,s=false)
PRICE
CARRID
CONNID
FLDATE
BOOKID
CUSTOMID
CLASS
PASSNAME
Structure SBOOK
Coding steps:
Obtain a reference to node and reference to the
metadata of the context node that will act as the new
node’s parent
Call static method create_nodeinfo_from_struct( ) to
create from a DDIC structure a node
11
© SAP AG 2005, ABAP Web Dynpro
Add a Dynamic Attribute to a Node
Context Root (c=1..1, s=true)
UI_ATTRIBUTES
BUTTON_VISIBILITY
TEXT_VISIBILITY
* add context attribute to node
data: Ui_Attributes_info type ref to If_Wd_Context_Node_info.
data: ls_att type WDR_CONTEXT_ATTRIBUTE_INFO.
* get node info of context
Ui_Attributes_info = Node_Ui_Attributes->get_node_info( ).
ls_att-name = `TEXT_VISIBILITY`.
ls_att-TYPE_NAME = 'WDUI_VISIBILITY'.
Ui_Attributes_info->add_attribute( ATTRIBUTE_INFO = ls_att ).
Coding steps:
Obtain a reference to the metadata of the parent node
that will contain the attribute
Fill structure ( WDR_CONTEXT_ATTRIBUTE_INFO )
with attribute properties
Add attribute to parent node
12
© SAP AG 2005, ABAP Web Dynpro
Principles of UI element manipulation
The following coding principles must be adhered to during UI element
manipulation:
1. Only perform direct manipulation of UI element objects when it is not
possible to control their behaviour through context binding.
2. UI manipulation is only permitted within the wdDoModifyView()
method of a view controller.
3. wdDoModifyView() has a boolean parameter called firstTime.
Typically, you will only build a dynamic UI element hierarchy when
firstTime == true. This avoids rebuilding the UI element hierarchy
unnecessarily.
4. Do NOT implement any coding in wdDoModifyView() that modifies
the context! The context should be considered “read-only” during the
execution of this method.
13
© SAP AG 2005, ABAP Web Dynpro
Dynamic UI manipulation (1)
Context Root
Connections
PRICE
CARRID
CONNID
FLDATE
Context Metadata UI Element Hierarchy to
be created at runtime
RootUIElementContainer
CARRIDLabel
CARRIDInput
CONNIDLabel
CONNIDInput
FLDATELabel
FLDATEInput
PRICELabel
PRICEInput
14
© SAP AG 2005, ABAP Web Dynpro
Dynamic UI manipulation (2)
Coding steps:
Check that this is the
first time the view has
been rendered
Obtain a reference to
the root UI element
container
UI Element Hierarchy to
be created at runtime
RootUIElementContainer
Context Root
Connections
PRICE
CARRID
CONNID
FLDATE
Context Metadata
method WDDOMODIFYVIEW .
data: wd_container type ref to cl_wd_uielement_container,
. . .
* Check if first time
check first_time = abap_true.
wd_container ?= view->get_element( 'ROOTUIELEMENTCONTAINER' ).
15
© SAP AG 2005, ABAP Web Dynpro
Dynamic UI manipulation (3)
Coding steps:
Create a new InputField UI
element object (bind to
context attribute
Create a new Label UI
element object
Set the Label’s properties
as required
Add the Label object to the
UI element container
Set the InputField’s
properties as required
Add the InputField to the
UI element container
InputField
UI Element Hierarchy to
be created at runtime
RootUIElementContainer
InputField
Label
Label
bind
add
Context Root
Connections
PRICE
CARRID
CONNID
FLDATE
Context Metadata
16
© SAP AG 2005, ABAP Web Dynpro
* Create label and input field
** create a input field
wd_input_field = cl_wd_input_field=>new_input_field( view = view
bind_value = 'CONNECTIONS.CARRID').
** create a label for the input field
wd_label = cl_wd_label=>new_label( label_for = wd_input_field->id ).
** set matrix_head_data for the label
cl_wd_matrix_head_data=>new_matrix_head_data( element = wd_label ).
** add label to container
wd_container->add_child( wd_label ).
** set matrix_head_data for the label
cl_wd_matrix_data=>new_matrix_data( element = wd_input_field ).
** add input field to container
wd_container->add_child( wd_input_field ).
Dynamic UI manipulation (4)
17
© SAP AG 2005, ABAP Web Dynpro
Dynamic Actions
Certain UI elements can trigger client-side events (e.g. pressing enter
in an InputField, toggling a CheckBox or selecting the row of a
table).
In order for the client-side event to trigger the execution of a server-
side method, Web Dynpro uses the concept of Actions.
Actions can either be assigned declaratively to UI element events at
design time, or dynamically at runtime.
Actions assigned dynamically can only refer to existing server-side
action handler methods. It is not possible to define the coding of an
action event handler dynamically; only to define which existing action
handler will be called when a client-side event is trapped.
18
The action can only be declared at design time.
© SAP AG 2005, ABAP Web Dynpro
Action Declaration
Declared action
Coding required
for dynamic
assigned action
19
A button can be created and be added to the UI element container.
© SAP AG 2005, ABAP Web Dynpro
* Create button
** create button UI element
wd_button = cl_wd_button=>new_button( text = 'Show Flights'
on_action = 'SELECT_FLIGHTS' ).
** set matrix_head_data for the label
cl_wd_matrix_head_data=>new_matrix_head_data( element = wd_button ).
** add button to container
wd_container->add_child( wd_button ).
Create a Dynamic Button
Coding steps:
Create a new Button UI
element object (assign an
predefined action)
Set the Button properties
as required
Add the Button to the UI
element container
Button
UI Element Hierarchy to
be created at runtime
RootUIElementContainer
InputField
Label
Context Root
Connections
PRICE
CARRID
CONNID
FLDATE
Context Metadata
Button
20
© SAP AG 2005, ABAP Web Dynpro
Was this a good approach?
Development Principle
Only if the required functionality of your application does not
permit design time declarations, then use a dynamic
modification approach.
All context node/attribute and UI elements which can be
created during design time should be created during design
time.
21
© SAP AG 2005, ABAP Web Dynpro
Example for Dynamic Programming
Display the content of
ANY table
Dynamic Context
Dynamic table UI element
Dynamic data retrieval
22
© SAP AG 2005, ABAP Web Dynpro
Example for Dynamic Programming I
DATA:
group_1 TYPE REF TO cl_wd_uielement_container,
new_tab TYPE REF TO cl_wd_table,
dyn_node TYPE REF TO if_wd_context_node,
tabname_node TYPE REF TO if_wd_context_node,
rootnode_info TYPE REF TO if_wd_context_node_info,
stru_tab TYPE REF TO data,
tablename TYPE string.
FIELD-SYMBOLS <tab> TYPE table.
* get node info of context root node
rootnode_info = wd_context->get_node_info( ).
* Get the name of the table to be created
tabname_node = wd_context->get_child_node( name = 'TABLE_DATA' ).
tabname_node->get_attribute( EXPORTING name = 'NAME' IMPORTING value =
tablename ).
translate tablename to upper case.
* create sub node of structure (tablename)
cl_wd_dynamic_tool=>create_nodeinfo_from_struct(
parent_info = rootnode_info
node_name = tablename
structure_name = tablename
is_multiple = abap_true ).
23
© SAP AG 2005, ABAP Web Dynpro
Example for Dynamic Programming II
* remove "old" table UI element from view , if necessary
group_1 ?= view->get_element( 'GROUP_1' ).
group_1->remove_child( id = 'TESTTAB' ).
* * get instance of new node
dyn_node = wd_context->get_child_node( name = tablename ).
DATA new_tab TYPE REF TO cl_wd_table.
* create new UI element table
new_tab = cl_wd_dynamic_tool=>create_table_from_node(
ui_parent = group_1
table_id = 'TESTTAB'
node = dyn_node ).
** fill context node with data
* create internal table of (tabletype)
CREATE DATA stru_tab TYPE TABLE OF (tablename).
ASSIGN stru_tab->* TO <tab>.
* Get table content
SELECT * FROM (tablename) INTO CORRESPONDING FIELDS OF TABLE <tab>.
* Bind internal table to context node
dyn_node->bind_table( <tab> ).
24
© SAP AG 2005, ABAP Web Dynpro
You should now be able to:
Understand what dynamic programming is
Dynamically modify and create UI elements
Dynamically create context elements
Dynamically bind UI element values to context
elements
Dynamically create actions
Web Dynpro Dynamic Programming: Summary

Mais conteúdo relacionado

Mais procurados

Table maintenance generator and its modifications
Table maintenance generator and its modificationsTable maintenance generator and its modifications
Table maintenance generator and its modificationsscribid.download
 
BATCH DATA COMMUNICATION
BATCH DATA COMMUNICATIONBATCH DATA COMMUNICATION
BATCH DATA COMMUNICATIONKranthi Kumar
 
Maximizing SAP ABAP Performance
Maximizing SAP ABAP PerformanceMaximizing SAP ABAP Performance
Maximizing SAP ABAP PerformancePeterHBrown
 
Smartforms interview questions with answers
Smartforms interview questions with answersSmartforms interview questions with answers
Smartforms interview questions with answersUttam Agrawal
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programmingRiccardo Cardin
 
ABAP Message, Debugging, File Transfer and Type Group
ABAP Message, Debugging, File Transfer and Type GroupABAP Message, Debugging, File Transfer and Type Group
ABAP Message, Debugging, File Transfer and Type Groupsapdocs. info
 
Call transaction method
Call transaction methodCall transaction method
Call transaction methodKranthi Kumar
 
230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-view
230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-view230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-view
230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-viewFaina Fridman
 
Using infoset query ,sap query and quick viewer
Using infoset query ,sap query and quick viewerUsing infoset query ,sap query and quick viewer
Using infoset query ,sap query and quick viewerbsm fico
 
ABAP Open SQL & Internal Table
ABAP Open SQL & Internal TableABAP Open SQL & Internal Table
ABAP Open SQL & Internal Tablesapdocs. info
 
ABAP Event-driven Programming &Selection Screen
ABAP Event-driven Programming &Selection ScreenABAP Event-driven Programming &Selection Screen
ABAP Event-driven Programming &Selection Screensapdocs. info
 

Mais procurados (20)

Bapi step-by-step
Bapi step-by-stepBapi step-by-step
Bapi step-by-step
 
Table maintenance generator and its modifications
Table maintenance generator and its modificationsTable maintenance generator and its modifications
Table maintenance generator and its modifications
 
BATCH DATA COMMUNICATION
BATCH DATA COMMUNICATIONBATCH DATA COMMUNICATION
BATCH DATA COMMUNICATION
 
SAP Adobe forms
SAP Adobe formsSAP Adobe forms
SAP Adobe forms
 
Maximizing SAP ABAP Performance
Maximizing SAP ABAP PerformanceMaximizing SAP ABAP Performance
Maximizing SAP ABAP Performance
 
Smartforms interview questions with answers
Smartforms interview questions with answersSmartforms interview questions with answers
Smartforms interview questions with answers
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programming
 
SAP Smart forms
SAP Smart formsSAP Smart forms
SAP Smart forms
 
Abap Questions
Abap QuestionsAbap Questions
Abap Questions
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
ABAP Message, Debugging, File Transfer and Type Group
ABAP Message, Debugging, File Transfer and Type GroupABAP Message, Debugging, File Transfer and Type Group
ABAP Message, Debugging, File Transfer and Type Group
 
Call transaction method
Call transaction methodCall transaction method
Call transaction method
 
230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-view
230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-view230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-view
230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-view
 
Io streams
Io streamsIo streams
Io streams
 
Exercise in alv
Exercise in alvExercise in alv
Exercise in alv
 
Using infoset query ,sap query and quick viewer
Using infoset query ,sap query and quick viewerUsing infoset query ,sap query and quick viewer
Using infoset query ,sap query and quick viewer
 
ABAP Open SQL & Internal Table
ABAP Open SQL & Internal TableABAP Open SQL & Internal Table
ABAP Open SQL & Internal Table
 
Abap Objects for BW
Abap Objects for BWAbap Objects for BW
Abap Objects for BW
 
ABAP Event-driven Programming &Selection Screen
ABAP Event-driven Programming &Selection ScreenABAP Event-driven Programming &Selection Screen
ABAP Event-driven Programming &Selection Screen
 
Files in java
Files in javaFiles in java
Files in java
 

Destaque

Creating simple comp
Creating simple compCreating simple comp
Creating simple compKranthi Kumar
 
IGROWSOFT abap material
IGROWSOFT abap materialIGROWSOFT abap material
IGROWSOFT abap materialKranthi Kumar
 
Ooabap notes with_programs
Ooabap notes with_programsOoabap notes with_programs
Ooabap notes with_programsKranthi Kumar
 
Sap abap-data structures and internal tables
Sap abap-data structures and internal tablesSap abap-data structures and internal tables
Sap abap-data structures and internal tablesMustafa Nadim
 
Chapter 08 abap dictionary objects views1
Chapter 08 abap dictionary objects views1Chapter 08 abap dictionary objects views1
Chapter 08 abap dictionary objects views1Kranthi Kumar
 
Using folder options for page protection
Using folder options for page protectionUsing folder options for page protection
Using folder options for page protectionKranthi Kumar
 
Binding,context mapping,navigation exercise
Binding,context mapping,navigation exerciseBinding,context mapping,navigation exercise
Binding,context mapping,navigation exerciseKranthi Kumar
 
Web(abap introduction)
Web(abap introduction)Web(abap introduction)
Web(abap introduction)Kranthi Kumar
 
Fi enhancement technique how-to-guide on the usage of business transaction ...
Fi enhancement technique   how-to-guide on the usage of business transaction ...Fi enhancement technique   how-to-guide on the usage of business transaction ...
Fi enhancement technique how-to-guide on the usage of business transaction ...Kranthi Kumar
 
Version it satya_dev
Version it satya_devVersion it satya_dev
Version it satya_devKranthi Kumar
 
Type casting in ooabap
Type casting in ooabapType casting in ooabap
Type casting in ooabapbiswajit2015
 
5078977 abap-tips
5078977 abap-tips5078977 abap-tips
5078977 abap-tipsjmts1000
 
Webdynpro by vijayender_reddy
Webdynpro by vijayender_reddyWebdynpro by vijayender_reddy
Webdynpro by vijayender_reddyKranthi Kumar
 

Destaque (20)

Creating simple comp
Creating simple compCreating simple comp
Creating simple comp
 
Creating messages
Creating messagesCreating messages
Creating messages
 
Data binding
Data bindingData binding
Data binding
 
IGROWSOFT abap material
IGROWSOFT abap materialIGROWSOFT abap material
IGROWSOFT abap material
 
Ooabap notes with_programs
Ooabap notes with_programsOoabap notes with_programs
Ooabap notes with_programs
 
Sap abap material
Sap abap materialSap abap material
Sap abap material
 
Sap abap-data structures and internal tables
Sap abap-data structures and internal tablesSap abap-data structures and internal tables
Sap abap-data structures and internal tables
 
Chapter 08 abap dictionary objects views1
Chapter 08 abap dictionary objects views1Chapter 08 abap dictionary objects views1
Chapter 08 abap dictionary objects views1
 
Creating a comp
Creating a compCreating a comp
Creating a comp
 
Using folder options for page protection
Using folder options for page protectionUsing folder options for page protection
Using folder options for page protection
 
Binding,context mapping,navigation exercise
Binding,context mapping,navigation exerciseBinding,context mapping,navigation exercise
Binding,context mapping,navigation exercise
 
Context at design
Context at designContext at design
Context at design
 
Web(abap introduction)
Web(abap introduction)Web(abap introduction)
Web(abap introduction)
 
Alv for web
Alv for webAlv for web
Alv for web
 
Fi enhancement technique how-to-guide on the usage of business transaction ...
Fi enhancement technique   how-to-guide on the usage of business transaction ...Fi enhancement technique   how-to-guide on the usage of business transaction ...
Fi enhancement technique how-to-guide on the usage of business transaction ...
 
Version it satya_dev
Version it satya_devVersion it satya_dev
Version it satya_dev
 
Abap faq
Abap faqAbap faq
Abap faq
 
Type casting in ooabap
Type casting in ooabapType casting in ooabap
Type casting in ooabap
 
5078977 abap-tips
5078977 abap-tips5078977 abap-tips
5078977 abap-tips
 
Webdynpro by vijayender_reddy
Webdynpro by vijayender_reddyWebdynpro by vijayender_reddy
Webdynpro by vijayender_reddy
 

Semelhante a Dynamic binding

Controllers and context programming
Controllers and context programmingControllers and context programming
Controllers and context programmingKranthi Kumar
 
SAP Inside Track 2010 - Thomas Jung Intro to WDA
SAP Inside Track 2010 - Thomas Jung Intro to WDASAP Inside Track 2010 - Thomas Jung Intro to WDA
SAP Inside Track 2010 - Thomas Jung Intro to WDAsjohannes
 
Lecture14 abap on line
Lecture14 abap on lineLecture14 abap on line
Lecture14 abap on lineMilind Patil
 
Introduction to Palm's Mojo SDK
Introduction to Palm's Mojo SDKIntroduction to Palm's Mojo SDK
Introduction to Palm's Mojo SDKBrendan Lim
 
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinWill your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinBarry Gervin
 
The ultimate guide to optimize your react native app performance in 2022
The ultimate guide to optimize your react native app performance in 2022The ultimate guide to optimize your react native app performance in 2022
The ultimate guide to optimize your react native app performance in 2022Katy Slemon
 
BP204 - Take a REST and put your data to work with APIs!
BP204 - Take a REST and put your data to work with APIs!BP204 - Take a REST and put your data to work with APIs!
BP204 - Take a REST and put your data to work with APIs!Craig Schumann
 
Nagios Conference 2012 - Dave Josephsen - Stop Being Lazy
Nagios Conference 2012 - Dave Josephsen - Stop Being LazyNagios Conference 2012 - Dave Josephsen - Stop Being Lazy
Nagios Conference 2012 - Dave Josephsen - Stop Being LazyNagios
 
AngularJS preso with directives and route resolve
AngularJS preso with directives and route resolveAngularJS preso with directives and route resolve
AngularJS preso with directives and route resolveBrent Goldstein
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Mahmoud Hamed Mahmoud
 
Planbox Backbone MVC
Planbox Backbone MVCPlanbox Backbone MVC
Planbox Backbone MVCAcquisio
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)Chiew Carol
 
Step by step guide to basic web dynpro abap
Step by step guide to basic web dynpro abapStep by step guide to basic web dynpro abap
Step by step guide to basic web dynpro abapKranthi Kumar
 
Moving from AS3 to Flex - advantages, hazards, traps
Moving from AS3 to Flex - advantages, hazards, trapsMoving from AS3 to Flex - advantages, hazards, traps
Moving from AS3 to Flex - advantages, hazards, trapsFlorian Weil
 
Become a Web-Dynpro for Functional Consultants - ConVista Asia
Become a Web-Dynpro for Functional Consultants - ConVista AsiaBecome a Web-Dynpro for Functional Consultants - ConVista Asia
Become a Web-Dynpro for Functional Consultants - ConVista AsiaConVista Consulting Asia
 
SAP WEBDYNPRO ABAP TRAINING
SAP WEBDYNPRO ABAP TRAININGSAP WEBDYNPRO ABAP TRAINING
SAP WEBDYNPRO ABAP TRAININGSanthosh Sap
 

Semelhante a Dynamic binding (20)

Controllers and context programming
Controllers and context programmingControllers and context programming
Controllers and context programming
 
SAP Inside Track 2010 - Thomas Jung Intro to WDA
SAP Inside Track 2010 - Thomas Jung Intro to WDASAP Inside Track 2010 - Thomas Jung Intro to WDA
SAP Inside Track 2010 - Thomas Jung Intro to WDA
 
Lecture14 abap on line
Lecture14 abap on lineLecture14 abap on line
Lecture14 abap on line
 
Introduction to Palm's Mojo SDK
Introduction to Palm's Mojo SDKIntroduction to Palm's Mojo SDK
Introduction to Palm's Mojo SDK
 
Web dynpro
Web dynproWeb dynpro
Web dynpro
 
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinWill your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
 
The ultimate guide to optimize your react native app performance in 2022
The ultimate guide to optimize your react native app performance in 2022The ultimate guide to optimize your react native app performance in 2022
The ultimate guide to optimize your react native app performance in 2022
 
BP204 - Take a REST and put your data to work with APIs!
BP204 - Take a REST and put your data to work with APIs!BP204 - Take a REST and put your data to work with APIs!
BP204 - Take a REST and put your data to work with APIs!
 
Building richwebapplicationsusingasp
Building richwebapplicationsusingaspBuilding richwebapplicationsusingasp
Building richwebapplicationsusingasp
 
Nagios Conference 2012 - Dave Josephsen - Stop Being Lazy
Nagios Conference 2012 - Dave Josephsen - Stop Being LazyNagios Conference 2012 - Dave Josephsen - Stop Being Lazy
Nagios Conference 2012 - Dave Josephsen - Stop Being Lazy
 
AngularJS preso with directives and route resolve
AngularJS preso with directives and route resolveAngularJS preso with directives and route resolve
AngularJS preso with directives and route resolve
 
Zend framework
Zend frameworkZend framework
Zend framework
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development
 
Planbox Backbone MVC
Planbox Backbone MVCPlanbox Backbone MVC
Planbox Backbone MVC
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)
 
Step by step guide to basic web dynpro abap
Step by step guide to basic web dynpro abapStep by step guide to basic web dynpro abap
Step by step guide to basic web dynpro abap
 
Moving from AS3 to Flex - advantages, hazards, traps
Moving from AS3 to Flex - advantages, hazards, trapsMoving from AS3 to Flex - advantages, hazards, traps
Moving from AS3 to Flex - advantages, hazards, traps
 
Become a Web-Dynpro for Functional Consultants - ConVista Asia
Become a Web-Dynpro for Functional Consultants - ConVista AsiaBecome a Web-Dynpro for Functional Consultants - ConVista Asia
Become a Web-Dynpro for Functional Consultants - ConVista Asia
 
Sap webdynpro abap training
Sap webdynpro abap trainingSap webdynpro abap training
Sap webdynpro abap training
 
SAP WEBDYNPRO ABAP TRAINING
SAP WEBDYNPRO ABAP TRAININGSAP WEBDYNPRO ABAP TRAINING
SAP WEBDYNPRO ABAP TRAINING
 

Mais de Kranthi Kumar

Chapter 07 debugging sap scripts
Chapter 07 debugging sap scriptsChapter 07 debugging sap scripts
Chapter 07 debugging sap scriptsKranthi Kumar
 
Chapter 06 printing sap script forms
Chapter 06 printing sap script formsChapter 06 printing sap script forms
Chapter 06 printing sap script formsKranthi Kumar
 
Chapter 05 sap script - configuration
Chapter 05 sap script - configurationChapter 05 sap script - configuration
Chapter 05 sap script - configurationKranthi Kumar
 
Chapter 04 sap script - output program
Chapter 04 sap script - output programChapter 04 sap script - output program
Chapter 04 sap script - output programKranthi Kumar
 
Chapter 02 sap script forms
Chapter 02 sap script formsChapter 02 sap script forms
Chapter 02 sap script formsKranthi Kumar
 
abap list viewer (alv)
abap list viewer (alv)abap list viewer (alv)
abap list viewer (alv)Kranthi Kumar
 

Mais de Kranthi Kumar (12)

Crm technical
Crm technicalCrm technical
Crm technical
 
control techniques
control techniquescontrol techniques
control techniques
 
Chapter 07 debugging sap scripts
Chapter 07 debugging sap scriptsChapter 07 debugging sap scripts
Chapter 07 debugging sap scripts
 
Chapter 06 printing sap script forms
Chapter 06 printing sap script formsChapter 06 printing sap script forms
Chapter 06 printing sap script forms
 
Chapter 05 sap script - configuration
Chapter 05 sap script - configurationChapter 05 sap script - configuration
Chapter 05 sap script - configuration
 
Chapter 04 sap script - output program
Chapter 04 sap script - output programChapter 04 sap script - output program
Chapter 04 sap script - output program
 
Chapter 02 sap script forms
Chapter 02 sap script formsChapter 02 sap script forms
Chapter 02 sap script forms
 
sap script overview
sap script overviewsap script overview
sap script overview
 
Batch input session
Batch input sessionBatch input session
Batch input session
 
Business workflow
Business workflowBusiness workflow
Business workflow
 
07 sap scripts
07 sap scripts07 sap scripts
07 sap scripts
 
abap list viewer (alv)
abap list viewer (alv)abap list viewer (alv)
abap list viewer (alv)
 

Dynamic binding

  • 2. 2 © SAP AG 2005, ABAP Web Dynpro Introduction Modifying the context structure at runtime Modifying the UI Element hierarchy at runtime The use of dynamic actions Contents: Dynamic Modifications at Runtime
  • 3. 3 © SAP AG 2005, ABAP Web Dynpro Dynamic Modifications at Runtime: Objectives After completing this lesson, you will be able to: Understand what dynamic programming is Dynamically modify and create UI elements Dynamically create context elements Dynamically bind UI element values to context elements Dynamically create actions
  • 4. 4 Dynamic Runtime Modifications Up till now, we have looked exclusively at the declarative approach to Web Dynpro programming. Now, we will turn our attention to the programmatic techniques needed to perform programmatically, the steps that have so far, only been done declaratively. © SAP AG 2005, ABAP Web Dynpro Dynamic Runtime Modifications What is type of dynamic modifications can be made at runtime? Dynamic Context Manipulation The creation, modification and deletion of context nodes and attributes Dynamic UI Manipulation The creation, modification and deletion of UI elements Dynamic Assignment of Actions to UI Elements
  • 5. 5 Dynamic Runtime Modifications Usually, you would declare the structure of a controller’s context at design time, and then create a static UI layout to display the data contained within the declared context. However, it is perfectly possible to create a context and UI layout hierarchy at runtime. These techniques should only be used when they are required! It is preferable to create as much of your context and UI layout hierarchy as possible at design time. © SAP AG 2005, ABAP Web Dynpro Dynamic Runtime Modifications There are several situations in which type of coding could be required: When the structure of your data is not known until runtime When you want the behaviour of a screen to be generic – and therefore dynamic When you are writing utility components that must function in a generic manner Etc… Under what circumstances should I write coding that performs dynamic modifications?
  • 6. 6 WDDOMODIFYVIEW This Standard Hook method is called just before the view layout is rendered. It is the only method in which the programmer is allowed direct access to the UI element objects themselves. The FIRSTTIME parameter is a boolean value that lets you know if the screen is being rendered for the very first time, or re-rendered in response to an Action event. © SAP AG 2005, ABAP Web Dynpro Standard Hook Method – View controller Only a view controller has these hook methods. The method WDDOMODIFYVIEW will only be called if: The view is part of the current view assembly and this is the first time the view is required, or The view is part of the current view assembly and an action belonging to the same view controller has been processed.
  • 7. 7 © SAP AG 2005, ABAP Web Dynpro Dynamic Context Data Creation Example of context metadata to be created dynamically?Context Root (c=1..1, s=true) FLIGHTS (c=0..n, s=true) Context Metadata to be created at runtime BOOKINGS (c=0..n, s=false) PRICE CARRID CONNID FLDATE BOOKID CUSTOMID CLASS PASSNAME
  • 8. 8 Context node creation All context nodes created by the application developer must have some other node acting as their parent. This is why a context is always supplied containing a root node. The root node is the anchor point for all other nodes, irrespective of whether they created statically at design time, or dynamically at runtime. Node creation principle 1.Create the node’s metadata 2.Create the node instance based on the new metadata © SAP AG 2005, ABAP Web Dynpro Coding steps: Obtain a reference to the metadata of the context node that will act as the new node’s parent. In this case, we are creating an independent node, therefore we get a reference to the metadata of the root node. Call static method create_nodeinfo_from_struct( ) from helper class cl_wd_dynamic_tool A DDIC Structure can be used for the attribute creation. Dynamic Value Node Creation (1) Context Root (c=1..1, s=true) FLIGHTS (c=0..n, s=true) Context Metadata to be created at runtime BOOKINGS (c=0..n, s=false) PRICE CARRID CONNID FLDATE BOOKID CUSTOMID CLASS PASSNAME DDIC Structure SFLIGHT
  • 9. 9 Creating an value node We are now dealing with the structure of the context not the contents, therefore we must work with the metadata that describes the context nodes and attributes, rather than the runtime data contained within node collections. This means we will be working with if_wd_context_node_info objects. 1.Get a reference to the metadata of the node acting as the parent of the new node. 2.Use method create_nodeinfo_from_struct from helper class cl_wd_dynamic_tool to create a node from a structure. © SAP AG 2005, ABAP Web Dynpro Dynamic Node Creation related to a structure Coding steps: Obtain a reference to the metadata of the context node that will act as the new node’s parent. Call static method create_nodeinfo_from_struct( ) from helper class cl_wd_dynamic_tool to create from a DDIC structure a node. DATA: rootnode_info TYPE REF TO if_wd_context_node_info, table_name type string value 'SFLIGHT', node_name type string value 'CONNECTIONS'. * get root node info of context rootnode_info = wd_context->get_node_info( ). * create node named CONNECTIONS of sflight cl_wd_dynamic_tool=>create_nodeinfo_from_struct( parent_info = rootnode_info node_name = node_name structure_name = table_name is_multiple = abap_false is_mandatory = abap_true ). Cardinality 1…1
  • 10. 10 © SAP AG 2005, ABAP Web Dynpro Dynamic Sub Node Creation related to a structure DATA: dyn_node type ref to if_wd_context_node, dyn_node_info TYPE REF TO if_wd_context_node_info, . . . * navigate from <CONTEXT> to <UI_ATTRIBUTES> via lead selection dyn_node = wd_Context->get_Child_Node( Name = node_name ). dyn_node_info = dyn_node->get_node_info( ). * create sub node named BOOKINGS of sbook cl_wd_dynamic_tool=>create_nodeinfo_from_struct( parent_info = dyn_node_info node_name = 'BOOKINGS' structure_name = 'SBOOK' is_multiple = abap_false is_mandatory = abap_true ). Context Root (c=1..1, s=true) FLIGHTS (c=0..n, s=true) BOOKINGS (c=0..n,s=false) PRICE CARRID CONNID FLDATE BOOKID CUSTOMID CLASS PASSNAME Structure SBOOK Coding steps: Obtain a reference to node and reference to the metadata of the context node that will act as the new node’s parent Call static method create_nodeinfo_from_struct( ) to create from a DDIC structure a node
  • 11. 11 © SAP AG 2005, ABAP Web Dynpro Add a Dynamic Attribute to a Node Context Root (c=1..1, s=true) UI_ATTRIBUTES BUTTON_VISIBILITY TEXT_VISIBILITY * add context attribute to node data: Ui_Attributes_info type ref to If_Wd_Context_Node_info. data: ls_att type WDR_CONTEXT_ATTRIBUTE_INFO. * get node info of context Ui_Attributes_info = Node_Ui_Attributes->get_node_info( ). ls_att-name = `TEXT_VISIBILITY`. ls_att-TYPE_NAME = 'WDUI_VISIBILITY'. Ui_Attributes_info->add_attribute( ATTRIBUTE_INFO = ls_att ). Coding steps: Obtain a reference to the metadata of the parent node that will contain the attribute Fill structure ( WDR_CONTEXT_ATTRIBUTE_INFO ) with attribute properties Add attribute to parent node
  • 12. 12 © SAP AG 2005, ABAP Web Dynpro Principles of UI element manipulation The following coding principles must be adhered to during UI element manipulation: 1. Only perform direct manipulation of UI element objects when it is not possible to control their behaviour through context binding. 2. UI manipulation is only permitted within the wdDoModifyView() method of a view controller. 3. wdDoModifyView() has a boolean parameter called firstTime. Typically, you will only build a dynamic UI element hierarchy when firstTime == true. This avoids rebuilding the UI element hierarchy unnecessarily. 4. Do NOT implement any coding in wdDoModifyView() that modifies the context! The context should be considered “read-only” during the execution of this method.
  • 13. 13 © SAP AG 2005, ABAP Web Dynpro Dynamic UI manipulation (1) Context Root Connections PRICE CARRID CONNID FLDATE Context Metadata UI Element Hierarchy to be created at runtime RootUIElementContainer CARRIDLabel CARRIDInput CONNIDLabel CONNIDInput FLDATELabel FLDATEInput PRICELabel PRICEInput
  • 14. 14 © SAP AG 2005, ABAP Web Dynpro Dynamic UI manipulation (2) Coding steps: Check that this is the first time the view has been rendered Obtain a reference to the root UI element container UI Element Hierarchy to be created at runtime RootUIElementContainer Context Root Connections PRICE CARRID CONNID FLDATE Context Metadata method WDDOMODIFYVIEW . data: wd_container type ref to cl_wd_uielement_container, . . . * Check if first time check first_time = abap_true. wd_container ?= view->get_element( 'ROOTUIELEMENTCONTAINER' ).
  • 15. 15 © SAP AG 2005, ABAP Web Dynpro Dynamic UI manipulation (3) Coding steps: Create a new InputField UI element object (bind to context attribute Create a new Label UI element object Set the Label’s properties as required Add the Label object to the UI element container Set the InputField’s properties as required Add the InputField to the UI element container InputField UI Element Hierarchy to be created at runtime RootUIElementContainer InputField Label Label bind add Context Root Connections PRICE CARRID CONNID FLDATE Context Metadata
  • 16. 16 © SAP AG 2005, ABAP Web Dynpro * Create label and input field ** create a input field wd_input_field = cl_wd_input_field=>new_input_field( view = view bind_value = 'CONNECTIONS.CARRID'). ** create a label for the input field wd_label = cl_wd_label=>new_label( label_for = wd_input_field->id ). ** set matrix_head_data for the label cl_wd_matrix_head_data=>new_matrix_head_data( element = wd_label ). ** add label to container wd_container->add_child( wd_label ). ** set matrix_head_data for the label cl_wd_matrix_data=>new_matrix_data( element = wd_input_field ). ** add input field to container wd_container->add_child( wd_input_field ). Dynamic UI manipulation (4)
  • 17. 17 © SAP AG 2005, ABAP Web Dynpro Dynamic Actions Certain UI elements can trigger client-side events (e.g. pressing enter in an InputField, toggling a CheckBox or selecting the row of a table). In order for the client-side event to trigger the execution of a server- side method, Web Dynpro uses the concept of Actions. Actions can either be assigned declaratively to UI element events at design time, or dynamically at runtime. Actions assigned dynamically can only refer to existing server-side action handler methods. It is not possible to define the coding of an action event handler dynamically; only to define which existing action handler will be called when a client-side event is trapped.
  • 18. 18 The action can only be declared at design time. © SAP AG 2005, ABAP Web Dynpro Action Declaration Declared action Coding required for dynamic assigned action
  • 19. 19 A button can be created and be added to the UI element container. © SAP AG 2005, ABAP Web Dynpro * Create button ** create button UI element wd_button = cl_wd_button=>new_button( text = 'Show Flights' on_action = 'SELECT_FLIGHTS' ). ** set matrix_head_data for the label cl_wd_matrix_head_data=>new_matrix_head_data( element = wd_button ). ** add button to container wd_container->add_child( wd_button ). Create a Dynamic Button Coding steps: Create a new Button UI element object (assign an predefined action) Set the Button properties as required Add the Button to the UI element container Button UI Element Hierarchy to be created at runtime RootUIElementContainer InputField Label Context Root Connections PRICE CARRID CONNID FLDATE Context Metadata Button
  • 20. 20 © SAP AG 2005, ABAP Web Dynpro Was this a good approach? Development Principle Only if the required functionality of your application does not permit design time declarations, then use a dynamic modification approach. All context node/attribute and UI elements which can be created during design time should be created during design time.
  • 21. 21 © SAP AG 2005, ABAP Web Dynpro Example for Dynamic Programming Display the content of ANY table Dynamic Context Dynamic table UI element Dynamic data retrieval
  • 22. 22 © SAP AG 2005, ABAP Web Dynpro Example for Dynamic Programming I DATA: group_1 TYPE REF TO cl_wd_uielement_container, new_tab TYPE REF TO cl_wd_table, dyn_node TYPE REF TO if_wd_context_node, tabname_node TYPE REF TO if_wd_context_node, rootnode_info TYPE REF TO if_wd_context_node_info, stru_tab TYPE REF TO data, tablename TYPE string. FIELD-SYMBOLS <tab> TYPE table. * get node info of context root node rootnode_info = wd_context->get_node_info( ). * Get the name of the table to be created tabname_node = wd_context->get_child_node( name = 'TABLE_DATA' ). tabname_node->get_attribute( EXPORTING name = 'NAME' IMPORTING value = tablename ). translate tablename to upper case. * create sub node of structure (tablename) cl_wd_dynamic_tool=>create_nodeinfo_from_struct( parent_info = rootnode_info node_name = tablename structure_name = tablename is_multiple = abap_true ).
  • 23. 23 © SAP AG 2005, ABAP Web Dynpro Example for Dynamic Programming II * remove "old" table UI element from view , if necessary group_1 ?= view->get_element( 'GROUP_1' ). group_1->remove_child( id = 'TESTTAB' ). * * get instance of new node dyn_node = wd_context->get_child_node( name = tablename ). DATA new_tab TYPE REF TO cl_wd_table. * create new UI element table new_tab = cl_wd_dynamic_tool=>create_table_from_node( ui_parent = group_1 table_id = 'TESTTAB' node = dyn_node ). ** fill context node with data * create internal table of (tabletype) CREATE DATA stru_tab TYPE TABLE OF (tablename). ASSIGN stru_tab->* TO <tab>. * Get table content SELECT * FROM (tablename) INTO CORRESPONDING FIELDS OF TABLE <tab>. * Bind internal table to context node dyn_node->bind_table( <tab> ).
  • 24. 24 © SAP AG 2005, ABAP Web Dynpro You should now be able to: Understand what dynamic programming is Dynamically modify and create UI elements Dynamically create context elements Dynamically bind UI element values to context elements Dynamically create actions Web Dynpro Dynamic Programming: Summary