KEMBAR78
Controllers and context programming | PDF
1
Controllers
and Context
Programming
2
© SAP AG 2005, ABAP Web Dynpro
The Context At Runtime
Understand the controller methods that are available
to you for application coding
The Context API
Contents:
Controller and Context Programming
3
© SAP AG 2005, ABAP Web Dynpro
After completing this lesson, you will be able to:
Understand how to access nodes and attributes in
the context using the context API.
The Context API: Objectives
4
Code Implementation
Each Web Dynpro controller is a separate ABAP program. The definition of these
programs is generated automatically when a new component or controller is
declared. The source code, that implements these controllers is generated
automatically. You are provided with various points within the controller code
where you may add your own coding.
Any attempt to entering coding outside the designated areas will result in that code
being lost when the controller is regenerated.
Every time the controller is activated the code is regenerated.
Standard Hook Methods
In every controller, there are certain standard methods that are always present. At
controller creation time, these methods are empty and can hold any coding the
developer wishes to place within them.
The application developer is not permitted to deleted or rename any of these
standard hook methods. If any attempt is made to do this, the changes will be lost
when the coding is regenerated.
© SAP AG 2005, ABAP Web Dynpro
Common Controller Features:
Standard Controller Hook Methods
Controller
Implementation
Standard
Hook
Methods
Instance
Methods
Context
Root Node
Required
Controllers
Controller
Interface
Other WD
Controllers
Custom
Controller
Business
Logic
(Models)
Created by explicit declaration or coding Created by the Web Dynpro Framework (WDF)
Component
Usage
Other WD
Components
5
WDDOINIT
Standard hook method for all Web Dynpro controllers. This method is only called
once during the lifecycle of a controller. All your initialization code should go here
since this method is called immediately after the controller has been instantiated.
WDDOEXIT
Standard hook method called at the end of a controller’s life cycle. All your
cleanup code should go here.
This method is called immediately before the controller’s lifecycle comes to an
end.
© SAP AG 2005, ABAP Web Dynpro
Standard Hook Methods for all controllers
All controllers have these two standard hook methods.
The method will only be called during the controller’s lifecycle if they
contain coding.
method WDDOINIT.
endmethod.
method WDDOEXIT.
endmethod.
6
Controller instance methods
This information applies to both view and custom controllers.
For all controllers, you can create an instance method by declaring the method
name and its parameters in the “methods” tab of the controller editor window.
© SAP AG 2005, ABAP Web Dynpro
Common Controller Features: Controller Instance Methods
Controller
Implementation
Standard
Hook
Methods
Instance
Methods
Context
Root Node
Required
Controllers
Controller
Interface
Other WD
Controllers
Custom
Controller
Business
Logic
(Models)
Created by explicit declaration or coding Created by the Web Dynpro Framework (WDF)
Component
Usage
Other WD
Components
7
Attributes:
Attributes can be public or private.
Attributes can not be directly used inside the controller. The attributes can be
accessed by using the controller attribute WD_THIS which provides a
reference to the local controller interface.
Methods:
All methods are public and can be used by any other controllers. Prerequisite
is that the controller which will call the method has defined a use relation to the
used controller in his properties.
© SAP AG 2005, ABAP Web Dynpro
Controller Attributes and Utility methods
Attributes for the controller can be created (public or private)
Arbitrary methods can be created - …….
8
WD_THIS
wdThis is the Web Dynpro specific self reference and should be used in
preference to the standard ABAP self reference of me. WD_THIS is a reference to
the current controller’s interface IF<controller name> and represents all the
functionality implemented in the generated class. This gives you access to
standard Web Dynpro functionality such as logging, validation, and parameter
mapping.
WD_CONTEXT
WD_CONTEXT is the reference to the controller’s context root node, and thus to the
entire context.
© SAP AG 2005, ABAP Web Dynpro
Standard Controller Attributes WD_CONTEXT and WD_THIS
WD_CONTEXT and WD_THIS
present in any WD controller (excepted interface and interface view
controller).
WD_THIS - self reference of the local interface, type depends on the
controller type.
WD_CONTEXT - reference to the context of associated controller.
9
© SAP AG 2005, ABAP Web Dynpro
Standard Controller Attribute WD_COMP_CONTROLLER
WD_COMP_CONTROLLER
present in any WD controller.
reference to the component controller with access to all public methods
and attributes.
Attribute will automatically assigned to all view controllers when a view
is created.
For all other controller the WD_COMP_CONTROLLER attribute will
be assigned, when the properties of the controller the component
controller is used.
10
wdDoBeforeNavigation()
This standard hook method is found only in the component controller.
Whenever an outbound plug is fired from a view controller, a navigation event is
raised. It is perfectly possible for each view in a view set to fire an outbound plug;
therefore, all navigation events are placed into a queue and are only processed
once all the views in the current view assembly have been processed. The
wdDoBeforeNavigation() method is called just before the Web Dynpro
Framework processes the events in the navigation queue. This allows you to
implement your own coding to do such things a navigation event prioritisation etc.
wdDoPostProcessing()
This standard hook method is found only in the component controller.
In complex Web Dynpro applications, it is possible that the data from multiple
components must be validated before the next step in the business process can
be taken. This method has been implemented in order for cross component
validation to take place.
© SAP AG 2005, ABAP Web Dynpro
Standard Hook Methods – Component Controller
Note: Only a component controller has these hook methods.
WDDOBEFORENAVIGATION
It is executed before the navigation stack is processed
WDDOPOSTPROCESSING
Data from multiple components can be validated before the next step is
execute
11
To access a context node element, the following steps must be performed:
1.Use the get_Child_Node() method to get a reference of If_Wd_Context_Node node
instance. This method requires the name of the node and optional the index of the element in
the parent node the desired node instance belongs to. In this case, the parent node is the
context root which only ever has one element, therefore the index parameter is 1.
© SAP AG 2005, ABAP Web Dynpro
Access to Attribute of Node Element I
Flights
..nCARRID
CONNID2CARRID
CONNID1CARRID
CONNID
Context Root
0Default
Element
data: Node_Flights type ref to If_Wd_Context_Node.
* navigate from <CONTEXT> to <FLIGHTS> via lead selection
Node_Flights = wd_Context->get_Child_Node( Name = `FLIGHTS` ).
* @TODO handle not set lead selection
if ( Node_Flights is initial ).
endif.
Note: Node and attribute
names must be
used in upper case
12
To access a context node element, the following steps must be performed:
1.Use the get_Child_Node() method to get a reference of If_Wd_Context_Node node
instance. This method requires the name of the node and optional the index of the element in
the parent node the desired node instance belongs to. In this case, the parent node is the
context root which only ever has one element, therefore the index parameter is 1.
2.Calling method get_Element() to get the element with the lead selection. This returns a
reference of If_Wd_Context_Element element instance.
© SAP AG 2005, ABAP Web Dynpro
Access to Attribute of Node Element II
Flights
..nCARRID
CONNID2CARRID
CONNID1CARRID
CONNID
Context Root
0Default
Element
data: Node_Flights type ref to If_Wd_Context_Node,
Elem_Flights type ref to If_Wd_Context_Element.
* navigate from <CONTEXT> to <FLIGHTS> via lead selection
Node_Flights = wd_Context->get_Child_Node( Name = `FLIGHTS` ).
* get element via lead selection
Elem_Flights = Node_Flights->get_Element( ).
* @TODO handle not set lead selection
if ( Elem_Flights is initial ).
endif.
13
To access a context node element, the following steps must be performed:
1.Use the get_Child_Node() method to get a reference of If_Wd_Context_Node node
instance. This method requires the name of the node and optional the index of the element in
the parent node the desired node instance belongs to. In this case, the parent node is the
context root which only ever has one element, therefore the index parameter is 1.
2.Calling method get_Element() to get the element with the lead selection. This returns a
reference of If_Wd_Context_Element element instance.
3.Calling method get_Attribute() to get the value of the attribute.
© SAP AG 2005, ABAP Web Dynpro
Access to Attribute of Node Element III
Flights
..nCARRID
CONNID2CARRID
CONNID1CARRID
CONNID
Context Root
0Default
Element
data: Node_Flights type ref to If_Wd_Context_Node,
Elem_Flights type ref to If_Wd_Context_Element,
Stru_Flights type If_Componentcontroller=>Element_Flights,
Item_CARRID like Stru_Flights-CARRID.
* navigate from <CONTEXT> to <FLIGHTS> via lead selection
Node_Flights = wd_Context->get_Child_Node( Name = `FLIGHTS` ).
* get element via lead selection
Elem_Flights = Node_Flights->get_Element( ).
* get single attribute
Elem_Flights->get_Attribute(
exporting
Name = `CARRID`
importing
Value = Item_Carrid ).
14
With the method get_Static_Attributes all static attributes of a context node can be
retrieved as a structure.
The method get_Static_Attributes will provide the values of the attributes by using
a move-corresponding. So the target structure can be different to the node
structure.
© SAP AG 2005, ABAP Web Dynpro
Access to all Static Attributes of a Node Element
Flights
..nCARRID
CONNID2CARRID
CONNID1CARRID
CONNID
Context Root
0Default
Element
data: Node_Flights type ref to If_Wd_Context_Node,
Elem_Flights type ref to If_Wd_Context_Element,
Stru_Flights type If_Componentcontroller=>Element_Flights.
* navigate from <CONTEXT> to <FLIGHTS> via lead selection
Node_Flights = wd_Context->get_Child_Node( Name = `FLIGHTS` ).
* get element via lead selection
Elem_Flights = Node_Flights->get_Element( ).
* get all declared attributes
Elem_Flights->get_Static_Attributes(
importing
Static_Attributes = Stru_Flights ).
15
With the method get_Static_Attributes_Table the attributes of all elements can be
retrieved as a internal table.
© SAP AG 2005, ABAP Web Dynpro
Access to all Elements of a Node
Flights
..nCARRID
CONNID2CARRID
CONNID1CARRID
CONNID
Context Root
0Default
Element
data: Node_Flights type ref to If_Wd_Context_Node,
Elem_Flights type ref to If_Wd_Context_Element,
lt_Flights type If_Main_View=>Elements_Flights .
* navigate from <CONTEXT> to <FLIGHTS> via lead selection
Node_Flights = wd_Context->get_Child_Node( Name = `FLIGHTS` ).
* @TODO handle not set lead selection
if ( Node_Flights is initial ).
endif.
* get all node element
Node_Flights->GET_STATIC_ATTRIBUTES_TABLE( importing
table = lt_Flights ).
Itab
16
Addition of elements to a node
The process of adding an element to a node requires the following steps:
1.Access the relevant context node. Use the get_Child_Node() method to get a reference of
If_Wd_Context_Node node instance.
© SAP AG 2005, ABAP Web Dynpro
Binding of an Element to a Node I
FLIGHTSContext Root
0Default
Element
data:
Node_Flights type ref to If_Wd_Context_Node.
* navigate from <CONTEXT> to <FLIGHTS> via lead selection
node_flights = wd_context->get_child_node( Name = 'FLIGHTS' ).
17
Addition of elements to a node
The process of adding an element to a node requires the following steps:
1.Access the relevant context node. Use the get_Child_Node() method to get a reference of
If_Wd_Context_Node node instance.
2.Create a new elements with the method create_element().
© SAP AG 2005, ABAP Web Dynpro
Binding of an Element to a Node II
FLIGHTSContext Root
0Default
Element
data:
Node_Flights type ref to If_Wd_Context_Node,
First_flight_Elem type ref to If_Wd_Context_Element.
* navigate from <CONTEXT> to <FLIGHTS> via lead selection
node_flights = wd_context->get_child_node( Name = 'FLIGHTS' ).
* create new element for node FLIGHTS
First_flight_Elem = Node_Flights->create_element( ).
18
Addition of elements to a node
The process of adding an element to a node requires the following steps:
1.Access the relevant context node. Use the get_Child_Node() method to get a reference of
If_Wd_Context_Node node instance.
2.Create a new elements with the method create_element().
3.Set the corresponding attributes to the element.
© SAP AG 2005, ABAP Web Dynpro
Binding of an Element to a Node III
FLIGHTSContext Root
0Default
Element
CARRID
CONNID
data:
Node_Flights type ref to If_Wd_Context_Node,
First_flight_Elem type ref to If_Wd_Context_Element.
* navigate from <CONTEXT> to <FLIGHTS> via lead selection
node_flights = wd_context->get_child_node( Name = 'FLIGHTS' ).
* create new element for node FLIGHTS
First_flight_Elem = Node_Flights->create_element( ).
* set attributes
First_flight_Elem->set_attribute( name = 'CARRID' value = 'LH' ).
First_flight_Elem->set_attribute( name = 'CONNID' value = '400' ).
19
Addition of element as a structure to a node
The process of adding an element as a structure to a node requires the following
steps:
1.Access the relevant context node. Use the get_Child_Node() method to get a reference of
If_Wd_Context_Node node instance.
2.Fill the required structure elements.
3.Set the corresponding attributes to the element.
4.Bind the element to the node. The parameter SET_INITIAL_ELEMENTS allows to delete all
existing elements of a node and bind only the actual element to the node. In this case the
parameter must be set to abap_true (default value). If the element should be added to the node
as an additional element then the parameter must be set to abap_false.
© SAP AG 2005, ABAP Web Dynpro
FLIGHTSContext Root
0Default
Element
CARRID
CONNID
1
Binding of an Element to a Node IV
data:
Node_Flights type ref to If_Wd_Context_Node,
First_flight_Elem type ref to If_Wd_Context_Element.
* navigate from <CONTEXT> to <FLIGHTS> via lead selection
node_flights = wd_context->get_child_node( Name = 'FLIGHTS' ).
* create new element for node FLIGHTS
First_flight_Elem = Node_Flights->create_element( ).
* set attributes
First_flight_Elem->set_attribute( name = 'CARRID' value = 'LH' ).
First_flight_Elem->set_attribute( name = 'CONNID' value = '400' ).
* bind first element to node
Node_Flights->bind_element( new_item = First_flight_Elem
SET_INITIAL_ELEMENTS = abap_false ).
20
Addition of element as a structure to a node
The process of adding an element as a structure to a node requires the following
steps:
1.Access the relevant context node. Use the get_Child_Node() method to get a reference of
If_Wd_Context_Node node instance.
2.Fill the required structure elements.
3.Set the corresponding attributes to the element.
4.Bind the structure to the node. The parameter SET_INITIAL_ELEMENTS allows to delete all
existing elements of a node and bind only the actual element to the node. In this case the
parameter must be set to abap_true (default value). If the structure should be added to the
node as an additional element then the parameter must be set to abap_false.
© SAP AG 2005, ABAP Web Dynpro
Static Attributes and Binding of a Element to a Node
data:
Node_Flights type ref to If_Wd_Context_Node,
Stru_flights type If_Componentcontroller=>Element_flights.
* navigate from <CONTEXT> to <FLIGHTS> via lead selection
node_flights = wd_context->get_child_node( Name = 'FLIGHTS' ).
* set values to node->attributes
Stru_flights-carrid = 'AA'.
Stru_flights-connid = '017'.
* bind new element to node
Node_flights->bind_structure( new_item = Stru_flights
SET_INITIAL_ELEMENTS = abap_false ).
21
Addition of multiple elements as a internal table to a node
The process of multiple elements as a internal table to a node requires the
following steps:
1.Define an internal table of the node type.
2.Define a structure of the table type.
3.Append values to the table.
4.Bind the internal table to the node.
© SAP AG 2005, ABAP Web Dynpro
FLIGHTSContext Root
0Default
Element
Binding of a Table to a Node
data:
Node_Flights type ref to If_Wd_Context_Node,
lt_flights type If_Componentcontroller=>Elements_flights,
Stru_flights like line of lt_flights.
* append values to local table
Stru_flights-carrid = 'LH'.
Stru_flights-connid = '400'.
append Stru_flights to lt_flights.
Stru_flights-carrid = 'AA'.
Stru_flights-connid = '017'.
append Stru_flights to lt_flights.
* get node reference
Node_Flights = wd_context->get_child_node( 'FLIGHTS' ).
* bind local table
Node_Flights->bind_table( lt_flights ).
CARRID
CONNID
1
Itab
CARRID
22
© SAP AG 2005, ABAP Web Dynpro
You should now be able to:
Understand how to access nodes and attributes in
the context using the context API
Controller and Context Programming: Summary

Controllers and context programming

  • 1.
  • 2.
    2 © SAP AG2005, ABAP Web Dynpro The Context At Runtime Understand the controller methods that are available to you for application coding The Context API Contents: Controller and Context Programming
  • 3.
    3 © SAP AG2005, ABAP Web Dynpro After completing this lesson, you will be able to: Understand how to access nodes and attributes in the context using the context API. The Context API: Objectives
  • 4.
    4 Code Implementation Each WebDynpro controller is a separate ABAP program. The definition of these programs is generated automatically when a new component or controller is declared. The source code, that implements these controllers is generated automatically. You are provided with various points within the controller code where you may add your own coding. Any attempt to entering coding outside the designated areas will result in that code being lost when the controller is regenerated. Every time the controller is activated the code is regenerated. Standard Hook Methods In every controller, there are certain standard methods that are always present. At controller creation time, these methods are empty and can hold any coding the developer wishes to place within them. The application developer is not permitted to deleted or rename any of these standard hook methods. If any attempt is made to do this, the changes will be lost when the coding is regenerated. © SAP AG 2005, ABAP Web Dynpro Common Controller Features: Standard Controller Hook Methods Controller Implementation Standard Hook Methods Instance Methods Context Root Node Required Controllers Controller Interface Other WD Controllers Custom Controller Business Logic (Models) Created by explicit declaration or coding Created by the Web Dynpro Framework (WDF) Component Usage Other WD Components
  • 5.
    5 WDDOINIT Standard hook methodfor all Web Dynpro controllers. This method is only called once during the lifecycle of a controller. All your initialization code should go here since this method is called immediately after the controller has been instantiated. WDDOEXIT Standard hook method called at the end of a controller’s life cycle. All your cleanup code should go here. This method is called immediately before the controller’s lifecycle comes to an end. © SAP AG 2005, ABAP Web Dynpro Standard Hook Methods for all controllers All controllers have these two standard hook methods. The method will only be called during the controller’s lifecycle if they contain coding. method WDDOINIT. endmethod. method WDDOEXIT. endmethod.
  • 6.
    6 Controller instance methods Thisinformation applies to both view and custom controllers. For all controllers, you can create an instance method by declaring the method name and its parameters in the “methods” tab of the controller editor window. © SAP AG 2005, ABAP Web Dynpro Common Controller Features: Controller Instance Methods Controller Implementation Standard Hook Methods Instance Methods Context Root Node Required Controllers Controller Interface Other WD Controllers Custom Controller Business Logic (Models) Created by explicit declaration or coding Created by the Web Dynpro Framework (WDF) Component Usage Other WD Components
  • 7.
    7 Attributes: Attributes can bepublic or private. Attributes can not be directly used inside the controller. The attributes can be accessed by using the controller attribute WD_THIS which provides a reference to the local controller interface. Methods: All methods are public and can be used by any other controllers. Prerequisite is that the controller which will call the method has defined a use relation to the used controller in his properties. © SAP AG 2005, ABAP Web Dynpro Controller Attributes and Utility methods Attributes for the controller can be created (public or private) Arbitrary methods can be created - …….
  • 8.
    8 WD_THIS wdThis is theWeb Dynpro specific self reference and should be used in preference to the standard ABAP self reference of me. WD_THIS is a reference to the current controller’s interface IF<controller name> and represents all the functionality implemented in the generated class. This gives you access to standard Web Dynpro functionality such as logging, validation, and parameter mapping. WD_CONTEXT WD_CONTEXT is the reference to the controller’s context root node, and thus to the entire context. © SAP AG 2005, ABAP Web Dynpro Standard Controller Attributes WD_CONTEXT and WD_THIS WD_CONTEXT and WD_THIS present in any WD controller (excepted interface and interface view controller). WD_THIS - self reference of the local interface, type depends on the controller type. WD_CONTEXT - reference to the context of associated controller.
  • 9.
    9 © SAP AG2005, ABAP Web Dynpro Standard Controller Attribute WD_COMP_CONTROLLER WD_COMP_CONTROLLER present in any WD controller. reference to the component controller with access to all public methods and attributes. Attribute will automatically assigned to all view controllers when a view is created. For all other controller the WD_COMP_CONTROLLER attribute will be assigned, when the properties of the controller the component controller is used.
  • 10.
    10 wdDoBeforeNavigation() This standard hookmethod is found only in the component controller. Whenever an outbound plug is fired from a view controller, a navigation event is raised. It is perfectly possible for each view in a view set to fire an outbound plug; therefore, all navigation events are placed into a queue and are only processed once all the views in the current view assembly have been processed. The wdDoBeforeNavigation() method is called just before the Web Dynpro Framework processes the events in the navigation queue. This allows you to implement your own coding to do such things a navigation event prioritisation etc. wdDoPostProcessing() This standard hook method is found only in the component controller. In complex Web Dynpro applications, it is possible that the data from multiple components must be validated before the next step in the business process can be taken. This method has been implemented in order for cross component validation to take place. © SAP AG 2005, ABAP Web Dynpro Standard Hook Methods – Component Controller Note: Only a component controller has these hook methods. WDDOBEFORENAVIGATION It is executed before the navigation stack is processed WDDOPOSTPROCESSING Data from multiple components can be validated before the next step is execute
  • 11.
    11 To access acontext node element, the following steps must be performed: 1.Use the get_Child_Node() method to get a reference of If_Wd_Context_Node node instance. This method requires the name of the node and optional the index of the element in the parent node the desired node instance belongs to. In this case, the parent node is the context root which only ever has one element, therefore the index parameter is 1. © SAP AG 2005, ABAP Web Dynpro Access to Attribute of Node Element I Flights ..nCARRID CONNID2CARRID CONNID1CARRID CONNID Context Root 0Default Element data: Node_Flights type ref to If_Wd_Context_Node. * navigate from <CONTEXT> to <FLIGHTS> via lead selection Node_Flights = wd_Context->get_Child_Node( Name = `FLIGHTS` ). * @TODO handle not set lead selection if ( Node_Flights is initial ). endif. Note: Node and attribute names must be used in upper case
  • 12.
    12 To access acontext node element, the following steps must be performed: 1.Use the get_Child_Node() method to get a reference of If_Wd_Context_Node node instance. This method requires the name of the node and optional the index of the element in the parent node the desired node instance belongs to. In this case, the parent node is the context root which only ever has one element, therefore the index parameter is 1. 2.Calling method get_Element() to get the element with the lead selection. This returns a reference of If_Wd_Context_Element element instance. © SAP AG 2005, ABAP Web Dynpro Access to Attribute of Node Element II Flights ..nCARRID CONNID2CARRID CONNID1CARRID CONNID Context Root 0Default Element data: Node_Flights type ref to If_Wd_Context_Node, Elem_Flights type ref to If_Wd_Context_Element. * navigate from <CONTEXT> to <FLIGHTS> via lead selection Node_Flights = wd_Context->get_Child_Node( Name = `FLIGHTS` ). * get element via lead selection Elem_Flights = Node_Flights->get_Element( ). * @TODO handle not set lead selection if ( Elem_Flights is initial ). endif.
  • 13.
    13 To access acontext node element, the following steps must be performed: 1.Use the get_Child_Node() method to get a reference of If_Wd_Context_Node node instance. This method requires the name of the node and optional the index of the element in the parent node the desired node instance belongs to. In this case, the parent node is the context root which only ever has one element, therefore the index parameter is 1. 2.Calling method get_Element() to get the element with the lead selection. This returns a reference of If_Wd_Context_Element element instance. 3.Calling method get_Attribute() to get the value of the attribute. © SAP AG 2005, ABAP Web Dynpro Access to Attribute of Node Element III Flights ..nCARRID CONNID2CARRID CONNID1CARRID CONNID Context Root 0Default Element data: Node_Flights type ref to If_Wd_Context_Node, Elem_Flights type ref to If_Wd_Context_Element, Stru_Flights type If_Componentcontroller=>Element_Flights, Item_CARRID like Stru_Flights-CARRID. * navigate from <CONTEXT> to <FLIGHTS> via lead selection Node_Flights = wd_Context->get_Child_Node( Name = `FLIGHTS` ). * get element via lead selection Elem_Flights = Node_Flights->get_Element( ). * get single attribute Elem_Flights->get_Attribute( exporting Name = `CARRID` importing Value = Item_Carrid ).
  • 14.
    14 With the methodget_Static_Attributes all static attributes of a context node can be retrieved as a structure. The method get_Static_Attributes will provide the values of the attributes by using a move-corresponding. So the target structure can be different to the node structure. © SAP AG 2005, ABAP Web Dynpro Access to all Static Attributes of a Node Element Flights ..nCARRID CONNID2CARRID CONNID1CARRID CONNID Context Root 0Default Element data: Node_Flights type ref to If_Wd_Context_Node, Elem_Flights type ref to If_Wd_Context_Element, Stru_Flights type If_Componentcontroller=>Element_Flights. * navigate from <CONTEXT> to <FLIGHTS> via lead selection Node_Flights = wd_Context->get_Child_Node( Name = `FLIGHTS` ). * get element via lead selection Elem_Flights = Node_Flights->get_Element( ). * get all declared attributes Elem_Flights->get_Static_Attributes( importing Static_Attributes = Stru_Flights ).
  • 15.
    15 With the methodget_Static_Attributes_Table the attributes of all elements can be retrieved as a internal table. © SAP AG 2005, ABAP Web Dynpro Access to all Elements of a Node Flights ..nCARRID CONNID2CARRID CONNID1CARRID CONNID Context Root 0Default Element data: Node_Flights type ref to If_Wd_Context_Node, Elem_Flights type ref to If_Wd_Context_Element, lt_Flights type If_Main_View=>Elements_Flights . * navigate from <CONTEXT> to <FLIGHTS> via lead selection Node_Flights = wd_Context->get_Child_Node( Name = `FLIGHTS` ). * @TODO handle not set lead selection if ( Node_Flights is initial ). endif. * get all node element Node_Flights->GET_STATIC_ATTRIBUTES_TABLE( importing table = lt_Flights ). Itab
  • 16.
    16 Addition of elementsto a node The process of adding an element to a node requires the following steps: 1.Access the relevant context node. Use the get_Child_Node() method to get a reference of If_Wd_Context_Node node instance. © SAP AG 2005, ABAP Web Dynpro Binding of an Element to a Node I FLIGHTSContext Root 0Default Element data: Node_Flights type ref to If_Wd_Context_Node. * navigate from <CONTEXT> to <FLIGHTS> via lead selection node_flights = wd_context->get_child_node( Name = 'FLIGHTS' ).
  • 17.
    17 Addition of elementsto a node The process of adding an element to a node requires the following steps: 1.Access the relevant context node. Use the get_Child_Node() method to get a reference of If_Wd_Context_Node node instance. 2.Create a new elements with the method create_element(). © SAP AG 2005, ABAP Web Dynpro Binding of an Element to a Node II FLIGHTSContext Root 0Default Element data: Node_Flights type ref to If_Wd_Context_Node, First_flight_Elem type ref to If_Wd_Context_Element. * navigate from <CONTEXT> to <FLIGHTS> via lead selection node_flights = wd_context->get_child_node( Name = 'FLIGHTS' ). * create new element for node FLIGHTS First_flight_Elem = Node_Flights->create_element( ).
  • 18.
    18 Addition of elementsto a node The process of adding an element to a node requires the following steps: 1.Access the relevant context node. Use the get_Child_Node() method to get a reference of If_Wd_Context_Node node instance. 2.Create a new elements with the method create_element(). 3.Set the corresponding attributes to the element. © SAP AG 2005, ABAP Web Dynpro Binding of an Element to a Node III FLIGHTSContext Root 0Default Element CARRID CONNID data: Node_Flights type ref to If_Wd_Context_Node, First_flight_Elem type ref to If_Wd_Context_Element. * navigate from <CONTEXT> to <FLIGHTS> via lead selection node_flights = wd_context->get_child_node( Name = 'FLIGHTS' ). * create new element for node FLIGHTS First_flight_Elem = Node_Flights->create_element( ). * set attributes First_flight_Elem->set_attribute( name = 'CARRID' value = 'LH' ). First_flight_Elem->set_attribute( name = 'CONNID' value = '400' ).
  • 19.
    19 Addition of elementas a structure to a node The process of adding an element as a structure to a node requires the following steps: 1.Access the relevant context node. Use the get_Child_Node() method to get a reference of If_Wd_Context_Node node instance. 2.Fill the required structure elements. 3.Set the corresponding attributes to the element. 4.Bind the element to the node. The parameter SET_INITIAL_ELEMENTS allows to delete all existing elements of a node and bind only the actual element to the node. In this case the parameter must be set to abap_true (default value). If the element should be added to the node as an additional element then the parameter must be set to abap_false. © SAP AG 2005, ABAP Web Dynpro FLIGHTSContext Root 0Default Element CARRID CONNID 1 Binding of an Element to a Node IV data: Node_Flights type ref to If_Wd_Context_Node, First_flight_Elem type ref to If_Wd_Context_Element. * navigate from <CONTEXT> to <FLIGHTS> via lead selection node_flights = wd_context->get_child_node( Name = 'FLIGHTS' ). * create new element for node FLIGHTS First_flight_Elem = Node_Flights->create_element( ). * set attributes First_flight_Elem->set_attribute( name = 'CARRID' value = 'LH' ). First_flight_Elem->set_attribute( name = 'CONNID' value = '400' ). * bind first element to node Node_Flights->bind_element( new_item = First_flight_Elem SET_INITIAL_ELEMENTS = abap_false ).
  • 20.
    20 Addition of elementas a structure to a node The process of adding an element as a structure to a node requires the following steps: 1.Access the relevant context node. Use the get_Child_Node() method to get a reference of If_Wd_Context_Node node instance. 2.Fill the required structure elements. 3.Set the corresponding attributes to the element. 4.Bind the structure to the node. The parameter SET_INITIAL_ELEMENTS allows to delete all existing elements of a node and bind only the actual element to the node. In this case the parameter must be set to abap_true (default value). If the structure should be added to the node as an additional element then the parameter must be set to abap_false. © SAP AG 2005, ABAP Web Dynpro Static Attributes and Binding of a Element to a Node data: Node_Flights type ref to If_Wd_Context_Node, Stru_flights type If_Componentcontroller=>Element_flights. * navigate from <CONTEXT> to <FLIGHTS> via lead selection node_flights = wd_context->get_child_node( Name = 'FLIGHTS' ). * set values to node->attributes Stru_flights-carrid = 'AA'. Stru_flights-connid = '017'. * bind new element to node Node_flights->bind_structure( new_item = Stru_flights SET_INITIAL_ELEMENTS = abap_false ).
  • 21.
    21 Addition of multipleelements as a internal table to a node The process of multiple elements as a internal table to a node requires the following steps: 1.Define an internal table of the node type. 2.Define a structure of the table type. 3.Append values to the table. 4.Bind the internal table to the node. © SAP AG 2005, ABAP Web Dynpro FLIGHTSContext Root 0Default Element Binding of a Table to a Node data: Node_Flights type ref to If_Wd_Context_Node, lt_flights type If_Componentcontroller=>Elements_flights, Stru_flights like line of lt_flights. * append values to local table Stru_flights-carrid = 'LH'. Stru_flights-connid = '400'. append Stru_flights to lt_flights. Stru_flights-carrid = 'AA'. Stru_flights-connid = '017'. append Stru_flights to lt_flights. * get node reference Node_Flights = wd_context->get_child_node( 'FLIGHTS' ). * bind local table Node_Flights->bind_table( lt_flights ). CARRID CONNID 1 Itab CARRID
  • 22.
    22 © SAP AG2005, ABAP Web Dynpro You should now be able to: Understand how to access nodes and attributes in the context using the context API Controller and Context Programming: Summary