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

Enhancing a controller

 

Controller parts created in the original component cannot be changed or deleted using the enhancement implementation.

 

Controller parts include the nodes, controller attributes and the methods.

 

Context node and Attributes:

 

For each existing context, Context node and attributes can be added to the component. If you wish to add an attribute to the existing node then there arise a two kind of situations.

 

1.      If the context node is without a dictionary structure then the attributes can be added to the node without any restrictions.

2.      If the context node is with dictionary structure you can only add attributes from the dictionary structure.

 

clip_image002

 

The nodes and attributes will be created with an additional property enhancement implementation.

 

Methods:

 

It is possible to create and implement a new method in the enhancement. In addition to that we can also modify the functionality of the existing method in the following three ways.

 

1.      Pre-Exit

2.      Post-Exit

3.      Overwrite-Exit

 

clip_image004

Technically, here we do not modify the source code of the existing method. Instead when we opt for the exit method a new method will be created and it’s just the sequence in which they are executed differs.

 

However the new method created will have the same interface as the existing method. (Importing, returning and exporting parameters etc.)

 

Pre-Exit:

This method will be called before the execution of the existing method. This method will first called by the controller using wd_this reference and later on original method of the controller will be called after the execution of pre-exit method using me object reference.

 

Post-Exit:

In contrast to the pre-exit, the post exit method will be called after the execution of the original method.

 

Overwrite Exit:

The overwrite exit method replaces the execution of original method by itself. In the previous two types of exit the original method gets executed either before or after the exit method whereas in overwrite exit execution of original method is replaced by the method created and controller will not call the existing method.

 

 

Attribute:

 

In addition to the methods and context nodes, controller attributes can also be created and used within the methods.

 

 

Now let us see a simple example on enhancing a controller.

 

Pre-requisites: Go through the document enhancing a view.

 

Link: Enhancing a view

 

 

In the previous post enhancing a view we gone through how to enhance a view, now let’s see an example of how to enhance a controller of the same component demotree.

 

clip_image005

 

Scenario: We have a supply function method in the controller supply_motor_kind which provides the value for the context node kind. Let’s create an exit method to add our own values to the context node.

clip_image006 

 

 

Step 1: We will proceed with the same component in the post enhancing a view and modification will be done on same enhancement project. If not create a new enhancement implementation and proceed.

 

Ref to link: Enhancing a view

 

 

Step 2: Go to the methods tab of the view controller and click on overwrite exit method.

 

A overwrite method of an existing method will be created with the same interface as the original method.

 

clip_image007

 

 

Write the coding to fill in the context node.

 

 

  DATA LT_MOTOR_KIND TYPE WD_THIS->ELEMENTS_MOTOR_KIND.
 
DATA LS_MOTOR_KIND LIKE LINE OF
  LT_MOTOR_KIND.

  LS_MOTOR_KIND-NAME =
'CAR'
.
  LS_MOTOR_KIND-
VALUE = 'CAR'
.
 
APPEND LS_MOTOR_KIND TO
LT_MOTOR_KIND.
 
CLEAR
LS_MOTOR_KIND.

  LS_MOTOR_KIND-NAME =
'BIKE'
.
  LS_MOTOR_KIND-
VALUE = 'BIKE'
.
 
APPEND LS_MOTOR_KIND TO
LT_MOTOR_KIND.
 
CLEAR
LS_MOTOR_KIND.

  NODE->BIND_TABLE( NEW_ITEMS = LT_MOTOR_KIND SET_INITIAL_ELEMENTS = ABAP_TRUE ).

 

 

 

Save and activate the component and test the application.

 

 

Output:

 

clip_image011

 

 

In a similar way try to create pre-exit and post exit method and add some values to the context node.

 

 You can now try to create a node and bind it to the UI elements created as the part of enhancement and create action for UI element and process the nodes in it.

 

 

 

About Arun

0 Comments:

Post a Comment

Powered by Blogger.