Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 17

IBM Global Business Services

Web Dynpro for ABAP


The Context at Design Time
IBM Corporation 2013

IBM Global Business Services

Session Overview
At design time, the developer can statically define the context structure of any
controller.
Context elements have to be added to the structure hierarchy and properties
have to be set for each context element.
At runtime, these properties rule the memory allocation, for example, the type
of the content and the dimension of data arrays to be stored. Thus it is
essential to understand the static definitions and the runtime properties related
to the context .
This lesson gives a basic introduction to the context.

Topic Title | Jan-2007

IBM Corporation 2013

IBM Global Business Services

Learning Objectives
After completing this lesson, you will be able to:
Define nodes and attributes in a controller's context
Explain how the node property's cardinality and singleton influence the memory
allocation at runtime
Define the Supply function methods for populating the context at runtime.

Topic Title | Jan-2007

IBM Corporation 2013

IBM Global Business Services

Defining the Context Structure


Every Web Dynpro controller has exactly
one hierarchical data storage structure,
known as context.
The data held in the context exists only
for the life span of the controller.
Once the controller instance has been
terminated, all data held within its context
is lost.
The structure (that is, the meta data) of a
context will typically be defined at design
time. However, at runtime, it is possible
not only to modify the contents of the
context, but also to modify its structure
itself.

Topic Title | Jan-2007

IBM Corporation 2013

IBM Global Business Services

Context Node and Attributes

Root Context
Node

Context Node

Context Node
Arranged hierarchically
Permitted to have children(Nodes and
Attributes)
Metadata Description declared manually
or derived from DDIC structure

Context Attribute
Stores runtime data or references to
runtime data
Based on DDIC types

Context Node
attributes

Context Node Properties

Topic Title | Jan-2007

IBM Corporation 2013

IBM Global Business Services

Context Element Properties : Structure at Design Time


All context nodes are collections
A node collection is composed of
elements
An element is an aggregation of
nodes immediate children
(attributes and/or nodes)
The cardinality controls the
number of elements that may be
held by a node collection at
runtime.

Topic Title | Jan-2007

IBM Corporation 2013

IBM Global Business Services

Context Element Properties : Basic rules


No mapping can be defined for the root node CONTEXT
For each context you can create either attributes or nodes beneath the root
node.
No mapping can be defined for individual attributes
All nodes must have a unique name within a context
All child elements within a node must have a unique name
Names of context elements may contain letters and numbers, but no special
characters

Topic Title | Jan-2007

IBM Corporation 2013

IBM Global Business Services

Cardinality of a Context Node

Every context node has a property


called cardinality.
This property is composed of two
values that, taken together,
describe the maximum and
minimum number of elements the
node collection may hold at
runtime

Topic Title | Jan-2007

IBM Corporation 2013

IBM Global Business Services

Cardinality of a Context Node : Possible cardinality values


There are four possible cardinality values (specified as <Min>..<Max>) :
11 :
Only one element is instantiated.

01 :
At runtime, no more than one element is instantiated, but it is also possible that no
element is instantiated.

1n :
n elements can be instantiated, but at least one element must be instantiated.

0n
The number of instantiated elements of the context node can vary

Topic Title | Jan-2007

IBM Corporation 2013

IBM Global Business Services

Lead Selection Property


At runtime, exactly one of the element
instances of a node can be accessed
using a 1-based index value.
The lead selection of a context node
points to either a single selected node
element (value of the lead selection =
number of the selected node element) or,
if no element is selected, it has the value
of the constant :
IF_WD_CONTEXT_NODE=>NO_SELEC
TION.

10

Topic Title | Jan-2007

IBM Corporation 2013

IBM Global Business Services

Lead Selection Property (Contd.)


The lead selection can be set automatically
by the Web Dynpro framework if the context
node property Initialize Lead Selection is set
to true. In this case, the first element in a
collection will automatically be marked as the
element at lead selection.
The lead selection can also be set by
program source code

Initialize Lead
Selection

Following two methods are available for


this:
IF_WD_CONTEXT_NODE interface:

SET_LEAD_SELECTION and
SET_LEAD_SELECTION_INDEX

Default: Yes (lead selection automatic, and


set to the first element of a node)

11

Topic Title | Jan-2007

IBM Corporation 2013

IBM Global Business Services

The Singleton Property


The Boolean property Singleton
critically affects the relationship
between a dependent node and its
parent node.
For each instance of child node is
related to the respective element in
the parent node collection.
Notice that the arrows pointing to
each of the child node collections
originate from each element in the
parent node.
Therefore, if there are n elements in
the parent node, then there will be n
distinct instances of a non-singleton
child node.

12

Topic Title | Jan-2007

IBM Corporation 2013

IBM Global Business Services

The Singleton Property (Contd.)


If the node child node has its Singleton
property set to true (which is the default),
it does not matter how many elements
are present in the parent node collection
There will only ever be one instance of
the child node

Singleton Property

13

Topic Title | Jan-2007

IBM Corporation 2013

IBM Global Business Services

The Singleton Property (Contd.)


Web Dynpro follows the principle of
lazy data instantiation.
It means that unless the program
actually needs to look at the data in
a child node, the child node will
remain unprocessed. Hence, there
is no need to hold multiple instances
of data the user has not requested.
The creation of a collection of the
dependent node is delayed to the
point when the related element of
the parent collection gets the lead
selection.

14

Topic Title | Jan-2007

IBM Corporation 2013

IBM Global Business Services

Supply function
Supply functions are a mechanism to repopulate child nodes
They can be assigned to each context node of a controller and is especially
useful in combination with singleton nodes.
If the lead selection is changed by the user, the supply function can access the
new lead selection element and recalculate the values of the child node
elements accordingly.
They are called automatically at runtime by the Web Dynpro Framework in the
following conditions
The node collection is initial.
The lead selection in the parent node collection is changed.
The node collection is invalidated programmatically.

15

Topic Title | Jan-2007

IBM Corporation 2013

IBM Global Business Services

Repopulating a Dependent Singleton Node: Supply Function

Supply Function

16

Topic Title | Jan-2007

IBM Corporation 2013

IBM Global Business Services

Session Summary
You should now be able to:
Define nodes and attributes in a controller's context
Explain how the node property's cardinality and singleton influence the
memory allocation at runtime
How to use Supply function method for population context.

17

Topic Title | Jan-2007

IBM Corporation 2013

You might also like