Hi, I provide training in SAP UI5. Also feel free to checkout my new web page https://saptechblog.com
Webdynpro ABAP

Supply Function

Supply functions are assigned to the context node of the controller. This function is called by the runtime when the context node is accessed.

Supply functions are called when:
1. One or more elements of the context node are accessed.
2. Context node is not filled yet or Initial
3. Context node has been invalidated in previous step

Why should one go for supply function when they can even initialize the values for the node in the DOINIT method of controller? DOINIT method is called only at the time of initialization of the component whereas supply function is called each and every time the element of the context node is accessed. Say for example you have a parent node and a child node. If you wanted to initialize the values of the child node based on the values of the parent node then you can use supply function to do the job.

Supply function is especially useful in combination with singleton nodes. The values of child node elements of the type Singleton depend on the element of the parent node to which the lead selection is currently assigned. 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.

Singleton Node:

Singleton node property specifies that the elements of the node are instantiated only for the element that bears the lead selection. If the lead selection was initialized automatically then the first element gets initialized automatically. For more information on singleton property and lead selection refer to sap link:

http://help.sap.com/saphelp_nw70ehp2/helpdata/en/47/45641880f81962e10000000a114a6b/frameset.htm

 

Let’s us create an example that explains the supply function and singleton property.

Step 1: Go to the Tcode SE80 and create a webdynpro component.

clip_image001

 

Assign the component to the package or save it in the local object.

Step 2: Go to the layout tab of the view controller and create a context node as shown below.

 

clip_image002

Enter the name for the node and press enter.

clip_image003

 

Create a child node for the node as shown below.

 

 

clip_image004

 

Enter the name, choose the cardinality for the node and provide the name for the supply function and press enter.

 

clip_image005

Create an attribute for the node “TYPES” of type string.

clip_image006

 

Enter the name and type for the attribute and press enter.

 

clip_image007

 

 

Create a Sub node for the node “TYPES” as shown below.

 

clip_image008

Enter the name, cardinality and name for the supply function.

 

clip_image009

 

Create an attribute to the sub node of type string.

 

clip_image009[1]

 

Your context node structure will now look like.

 

clip_image010

 

Step 3: Go to the layout tab of the view controller and insert a tree UI element.

clip_image011

 

Provide the ID and type for the UI element.

 

clip_image012

 

 

Bind the data source property of the Tree UI element to the Node “NODE”.

clip_image013

Fill the properties of the Tree UI element as shown below.

clip_image014

 

Right click on the tree UI element and choose insert node type.

 

clip_image015

Provide the ID and type.

clip_image016

 

Bind the data source property to the node “TYPES” and text property to the text attribute of the node “TYPES”.

 

clip_image017

 

 

clip_image018

 

Again right click on tree UI element and select insert node type.

 

clip_image019

 

Provide ID and type. This time choose the node type as Item to be displayed as the subtype.

 

clip_image020

 

Bind the data source property to the node “SUBTYPE” and text property to the text attribute of the node “SUBTYPE”.

 

clip_image021

 

 

clip_image022

 

Step 4: Go to the methods tab of the view controller. Write the following code in the supply created for the node “TYPES”.

The importing parameter node will contain the object reference for that node.

 

clip_image023

 

Code:

DATA ls_types TYPE wd_this->Element_types.
DATA lt_types TYPE wd_this->Elements_types.

ls_types
-text = 'Type1'.
append ls_types to lt_types.
clear ls_types.

ls_types
-text = 'Type2'.
append ls_types to lt_types.
clear ls_types.

ls_types
-text = 'Type3'.
append ls_types to lt_types.
clear ls_types.

node
->bind_table( new_items = lt_types set_initial_elements = abap_true ).

 

In the supply function method created for the node “SUBTYPE” Write the following code.

 

 

clip_image024

 

Code:

DATA ls_subtype TYPE wd_this->Element_subtype.
DATA lt_subtype TYPE wd_this->Elements_subtype.

ls_subtype-text = 'Sub Type1'.
append ls_subtype to lt_subtype.
clear ls_subtype.

ls_subtype-text = 'Sub Type2'.
append ls_subtype to lt_subtype.
clear ls_subtype.

ls_subtype-text = 'Sub Type3'.
append ls_subtype to lt_subtype.
clear ls_subtype.

node->bind_table( new_items = lt_subtype set_initial_elements = abap_true ).

 

Save and activate the whole component.

Step 5: Create an application for the component and test the component.clip_image025

 

 

Output:

Set the break point on the both the supply function methods and check when the methods are being called.

By the time of executing the component the supply function for the type will be called once and the subtype will be called thrice as we have three elements (Three records) in the “TYPE” node.

 

clip_image026

 

Expand the nodes. You can see all the nodes filled with values.

 

clip_image027

 

 

Now go to the context tab of the view controller and set the singleton property for the child node subtype and check the output.

 

 

clip_image028

 

Check in the debugger you can see the supply function for the subtype is called only once i.e for the first element for which the lead is initialized.

 

About Arun

0 Comments:

Post a Comment

Powered by Blogger.