Embedding A BRFplus Object in An ABAP WebDynpro Application
Embedding A BRFplus Object in An ABAP WebDynpro Application
Applies to:
Business Rule Framework plus (BRFplus) shipped with SAP NetWeaver 7.0 Enhancement Package 1.
For a detailed introduction to BRFplus please visit Business Rules Management at the SDN network and
select „BRFplus‟ in the Related Content section.
Summary
This paper is about the integration of a BRFplus object into your ABAP WebDynpro application. It shows
you step by step how to embed the object and modify its UI, introduces you to events which can be
raised by the embedded object and explains how to deal with exceptions.
The document gives you advise concerning some aspects of the used component like deallocating of
resources when the object is forced to close or how to handle user actions in a confirmation dialog
displayed by the embedded object.
Author's Bio
Daniel Schüler and Patrick Lorenz are students of Information Technology at the
University of Corporate Education in Karlsruhe. They joined SAP in 2008. During their
vocational training they work at different departments at SAP, mainly in the
development area.
Thomas Albrecht is a developer in the team of Business Rule Framework plus. Since joining
SAP in 2003, he has worked in and driven several development projects in ERP Travel
Management with focus on architecture. In 2008, he joined the BRFplus development team.
Table of Contents
Use of the Object Manager component to embed BRF+ objects ................................................................... 3
Integration of the Object Manager component ............................................................................................................. 3
Use of the Object Manager component methods ......................................................................................................... 5
Edit and save a BRFplus object with the object manager .............................................................................. 5
Create a BRFplus object with the object manager ......................................................................................... 6
Free resources ................................................................................................................................................ 7
Handle user action in the confirmation dialog ................................................................................................. 7
Modifying the UI of the embedded object ....................................................................................................... 9
Direct configuration (7.0/7.1 EHP 1) ............................................................................................................................ 9
Configuration through a UI mode class (7.0/7.1 EHP2) ............................................................................................. 10
Handling exceptions in the object manager .................................................................................................. 11
IMPORTANT: Definition of exceptions in the interface of the object manager in releases 7.0 and 7.1 ...................... 11
Catching more specific exceptions when calling methods of the object manager ...................................................... 11
Overview of the Object Manager .................................................................................................................. 13
Interfaces used to configure the UI-Modes ................................................................................................... 13
Prerequisites
Basic knowledge of ABAP Web Dynpro
Basic knowledge of BRFplus
Learning Objectives
After this tutorial you can…
embed a BRFplus object into your Web Dynpro application
modify the UI of the BRFplus object according to your needs
use and react on different events which are provided by the BRFplus Object Manager
Procedure
Use of the Object Manager component to embed BRF+ objects
In this first example we create a small Web Dynpro component which is able to display and close a
BFRplus object. You will learn how to create, instantiate and use the Object Manager component
provided by the BRFplus framework.
2. Afterwards, you have to add the Object Manager component usage of the component controller
of your component.
On the Properties tab of your component controller, choose Create Controller Usage. Then,
choose the interface controller of the component FDT_IWD_OBJECT_MANAGER from the list in
the popup.
3. Now we need a place on one of our views to display the BRFplus object. Navigate to the layout
tab of that view and create a ViewContainerUIElement. Also add two buttons on the view which
will be used later to display and close our object. Your view could look like this:
Now you can embed the “main_window” of the implemented Object Manager component in your
ViewContainerUIElement. To do so, navigate to the window of your component, select the
ViewContainer und choose Embed View. In the following dialogs, select the “MAIN_WINDOW” of
the Object Manager.
4. To fill our ViewContainerUIElement, we need to create an instance of our Object Manager first.
So choose a method in which we can instantiate our Object Manager component, for example
the method WDOINIT of your component controller.
Note: You have to choose a method which is called before the view in which you implemented your
ViewContainerUIElement is displayed. Otherwise, the ViewContainer tries to display an object
which has no instance and will raise an exception.
Write the following code in your method to create an instance of your Object Manager
component (see comments for explanation):
" if the usage has no active component, create the object manager
" component
IF lo_usage->has_active_component( ) IS INITIAL.
cl_fdt_wd_factory=>if_fdt_wd_factory~get_instance( )->
if_fdt_wd_component_factory~create_object_manager_comp(
io_usage = lo_usage ).
ENDIF.
The preparation for the use of the Object Manager component is now done. In the next steps, you will
use this component to display and close a BRFplus object.
TRY .
“ call the method display() of the object manager interface with the
“ id of a BRFplus object to display the object in the viewcontainer
wd_this->wd_cpifc_object_manager( )->
display( iv_id = '00145EF41CBA02DD93ADEB45F6CA8A54' ).
CATCH cx_fdt_wd INTO lx_fdt_wd.
" if an exception occurs, forward the exception to the
“ report_exception() method together with a reference to the message “
manager of your component. A message will then be displayed at the “ top of
you WD-View
cl_fdt_wd_service=>report_exception(
EXPORTING
io_message_manager = wd_this->wd_get_api( )->
get_message_manager( )
ix_wd_exception = lx_fdt_wd ).
ENDTRY.
endmethod.
For the Display button, implement an event handler which calls the method above in the
component controller. Now you have created your first Web Dynpro application ready for
embedding a BRFplus object.
6. As a last step we implement the functionality of the Close button. The procedure is similar to the
integration of the Display button. Create a method in your component controller which you call in
the event handler of the Close button. The method should look like the one above but instead of
“wd_this-> wd_cpifc_object_manager( )->display(…)” you call “wd_this->
wd_cpifc_object_manager( )->close()”. See the table in the appendix for optional parameters to
this method.
Note: The “close()” method doesn‟t necessarily close a displayed object. In case the object has been modified and is
in an unsaved state and the IV_FORCE FLAG of the “close()” method is set to FALSE, a confirmation dialog
pops up. Here, the user can decide if he or she really wants to close the object.
See section “Handle user action in the confirmation dialog” to learn how to make sure that the embedded
object is closed.
You have successfully embedded a BRFplus object into your Web Dynpro application. In the next
chapter, you will see how you can open an object in edit mode, save changes to this object and find out
what you have to consider when you want to close a modified object.
1. First we add two buttons to our application for the additional functions „edit‟ and „save‟. When you
are done, your application may look like this:
TRY .
wd_this->wd_cpifc_object_manager( )->
edit( iv_id = '00145EF41CBA02DD93ADEB45F6CA8A54' ).
CATCH cx_fdt_wd INTO lx_fdt_wd.
cl_fdt_wd_service=>report_exception(
EXPORTING
io_message_manager = wd_this->wd_get_api( )->get_message_manager( )
ix_wd_exception = lx_fdt_wd ).
ENDTRY.
endmethod.
To save a displayed object, use the SAVE_CURRENT_OBJECT method offered by the interface
of the object manager.
3. To make the buttons work, we need to define event handlers for them where we call the
corresponding method of the component controller.
We have now completed the functionality to open an object in editing mode und save the current status
of the object.
Besides the main types (like application or function) you can also set subtypes of a data object by using
the SUBTYPE element of the structure S_OBJECT_TYPE_EXTENDED. The possible subtypes for a
data object begin with “GC_DATA_OBJECT_TYPE_” and the subtypes (expression types) for
expressions with “GC_EXTY_” (both defined in “IF_FDT_CONSTANTS”).
The last element of S_OBJECT_TYPE_EXTENDED is IS_ACTION. With this element, you can choose if
you want to create an expression (IS_ACTION = FALSE) or an action (IS_ACTION = TRUE) if the
chosen type is expression.
In the following code sample the available object types which can be created will be limited to a
“structure”:
Data: lt_object_types type if_fdt_wd_types=>t_object_type_extended,
ls_object_type type if_fdt_wd_types=>s_object_type_extended.
ls_object_type-type = if_fdt_constants=>gc_object_type_data_obect.
ls_object_type-subtype = if_fdt_constants=>gc_data_object_type_structure.
wd_this->wd_cpifc_object_manager( )->
create( IT_OBJECT_TYPE = lt_object_types ).
In the definition of the create method you will find further parameters to modify the popup.
Free resources
If the displaying client (e.g. browser) is closed, it also forces the Web Dynpro framework to close. The
problem is that all open objects and reserved resources have to be freed. To achieve this, call the
CLOSE method of the object manager with the IV_FORCE parameter set to ABAP_TRUE. In this case,
no dialog will be displayed asking to save changed objects, but locked objects are released and any
reserved resources are freed.
2. Add a method named HDL_STATE_CHANGE and choose Event Handler as method type.
3. With the F4 help button of the Event column, open the selection assistant and choose the
STATE_CHANGE event.
IF iv_transition EQ if_fdt_wd_state=>gc_transition_close.
ELSE.
ENDIF.
endmethod.
Note: You should not use hard-coded strings in any application because of translation issues. In this demo
application the attention is laid on the integration of the object manager. The comment “#EC NOTEXT” is used
to suppress the error message of the enhanced program testing.
Now we can determine what the user did in response to the confirmation dialog and implement the
application behavior in the event handler methods.
Registering for the cancellation event is similar to the given example. On the selection screen (see Figure
9), just choose the event STATE_CHANGE_CANCEL. This event helps to handle the user reaction in the
asynchronous Web Dynpro framework. It is triggered if the user cancels the creation of an object or
cancels closing an object that has not yet been saved.
The next part of the tutorial deals with the appearance of the UI and how it can be modified.
Note: Even though it is possible to modify the UI (and also using the the UI mode approach) in release 7.0 EHP 1,
the UI configuration is not fully enabled. To use the whole functionality you need at least release 7.0 with EHP
2 or release 7.1. In EHP1, the configuration concerning the object manager
(IF_FDT_WD_OBJM_CONFIGURATION) is available, as well as the setting to disable the table settings in the
decision table UI (IF_FDT_WD_CONFIGURATION=> C_PARAM_HIDE_TAB_SETTINGS)
iv_button_name = if_fdt_wd_objm_configuration=>gc_toolbar_button_transport
iv_is_visible = abap_false
).
ro_configuration->
if_fdt_wd_objm_configuration~set_general_data_visible(
iv_is_visible = abap_false
).
" 3. create a new Object Manager component with your configuration object
IF lo_usage->has_active_component( ) IS INITIAL.
cl_fdt_wd_factory=>if_fdt_wd_factory~get_instance( )->
if_fdt_wd_component_factory~create_object_manager_comp(
io_usage = lo_usage
io_configuration = ro_configuration ).
ENDIF.
Note: Even though the UI mode infrastructure is available in EHP 1, the user has no possibility to alter the
configuration settings via the user settings dialog. Also only some configuration parameters are available (see
last chapter).
1. Create a new class and add the UI mode class CL_FDT_WD_UI_SIMPLE_MODE as its
superclass.
3. In the redefined method, enter your configuration code. As an example, we hide the Transport
button of the toolbar and the General Data area in the following code:
ro_configuration->if_fdt_wd_objm_configuration~
set_general_data_visible( iv_is_visible = abap_false ).
4. In a last step, you have to set the UI mode of your embedded object to the newly created UI
mode class as shown in the following sample code:
IF wd_this->wd_cpuse_object_manager( )->
has_active_component( ) IS NOT INITIAL.
IMPORTANT: Definition of exceptions in the interface of the object manager in releases 7.0 and 7.1
In release 7.0, it is not possible to define exceptions for a method in ABAP Web Dynpro. That‟s
why it is important to know what type of exceptions could occur by calling a method of the object
manager. So it is necessary to have a look into the system.
In release 7.1 and later, the interface is updated with the exception definitions.
Note: All exceptions that occur in the backend (with root exception CX_FDT) are converted to the exception type
CX_FDT_WD_BACKEND by the UI layer.
Catching more specific exceptions when calling methods of the object manager
In some cases it is useful to react in different ways on exceptions. There could be a different procedure in
case an object is not editable or the user has insufficient authorizations.
To accomplish this, we just need to catch more specific exceptions. The package interface of
SFDT_WD_INFRASTRUCTURE offers the following exception types:
Let's go to the implementation of the EDIT method in the component controller. At this point, it should
look like this:
method EDIT .
TRY .
wd_this->wd_cpifc_object_manager( )->
edit( iv_id = '00145EF41CBA02DD93ADEB45F6CA8A54' ).
CATCH cx_fdt_wd INTO lx_fdt_wd.
cl_fdt_wd_service=>report_exception(
EXPORTING
io_message_manager = wd_this->wd_get_api( )->get_message_manager( )
ix_wd_exception = lx_fdt_wd ).
ENDTRY.
endmethod.
Now we insert an additional catch block into this implementation. It should catch the exception type
„CX_FDT_WD_OBJECT_LOCKED‟. If a fitting exception occurs the message „Object is locked by
another User‟ should be printed.
The new code should be similar to this:
METHOD edit .
TRY .
wd_this->wd_cpifc_object_manager( )->
edit( iv_id = '00145EF41CBA02DD93ADEB45F6CA8A54' ).
CATCH cx_fdt_wd_object_locked INTO lx_fdt_wd.
DATA: lv_message_text TYPE string.
lv_message_text = 'Object is locked by another User.'. "#EC NOTEXT
wd_this->wd_get_api( )->get_message_manager( )->report_message(
message_text = lv_message_text
message_type = if_wd_message_manager=>co_type_error ).
CATCH cx_fdt_wd INTO lx_fdt_wd.
cl_fdt_wd_service=>report_exception(
EXPORTING io_message_manager = wd_this->wd_get_api( )->
get_message_manager( )
ix_wd_exception = lx_fdt_wd ).
ENDTRY.
ENDMETHOD.
Method Description
Closes object(s). The confirmation Dialog can be suppressed by
CLOSE
setting the IV_FORCE_FLAG.
Displays a “Create” popup where the user can enter further
CREATE parameters. Object type and other options can be set to limit the
user‟s choices in the popup. May throw exception CX_FDT_WD
Deletes the object specified by iv_id. The user has to
DELETE
acknowledge this action. May throw exception CX_FDT_WD
Displays the object specified by IV_ID. May throw exception
DISPLAY
CX_FDT_WD
Opens the object specified by IV_ID for editing. May throw
EDIT
exception CX_FDT_WD
Returns the ID, state, and timestamp of the currently displayed
GET_DISPLAYED_OBJECT
object.
IS_OBJECT_DISPLAYED Indicates if an object is currently displayed.
IS_UNSAVED_OBJECT_EXISTING Indicates if an unsaved object exits.
Saves the current (visible) object. May throw exception
SAVE_CURRENT_OBJECT
CX_FDT_WD
Event Description
NAVIGATE_TO_OBJECT Navigate to object
STATE_CHANGE Change of UI state (transition)
STATE_CHANGE_CANCEL Change of UI state is cancelled by user
Interface Description
Related Content
BRFplus
Carsten Ziegler‟s Blog
Business Rules Management
Copyright
© Copyright 2009 SAP AG. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP
AG. The information contained herein may be changed without prior notice.
Some software products marketed by SAP AG and its distributors contain proprietary software components of other software
vendors.
Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.
IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10,
z9, iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise
Server, PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER, OpenPower, PowerPC,
BatchPipes, BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex,
MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM
Corporation.
Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.
Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems
Incorporated in the United States and/or other countries.
Oracle is a registered trademark of Oracle Corporation.
UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.
Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of
Citrix Systems, Inc.
HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts
Institute of Technology.
Java is a registered trademark of Sun Microsystems, Inc.
JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by
Netscape.
SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, and other SAP products and services
mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other
countries.
Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius,
and other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered
trademarks of Business Objects S.A. in the United States and in other countries. Business Objects is an SAP company.
All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document
serves informational purposes only. National product specifications may vary.
These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP
Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors
or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in
the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as
constituting an additional warranty.