Executing a BRFplus Decision Service from an …...functionality accessible via the SAP NetWeaver Gateway Interface. There are several ways to create the There are several ways to
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Business Rule Framework plus (BRFplus) shipped with SAP NetWeaver 7.0 Enhancement Package 2 or above. 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 document describes the execution of a BRFplus decision service from an Android based mobile device. The document also explains the creation of a NetWeaver Gateway Service for a simple BRFplus decision service.
Authors: Joydeep Paul, Saba Samrin
Company: SAP Labs India
Created on: 18 August, 2012
About the Authors
Joydeep Paul is an architect in the BRFplus team and has been working on the topic since 2008.
Saba Samrin is a scholar at SAP and is working as intern in BRFplus team. She joined the team on April 2012.
Business Scenario .............................................................................................................................................. 3
Background Information ...................................................................................................................................... 3
Creating the Body-Mass Index decision service in BRFplus .......................................................................... 3
Creating Remote-Enabled Function ................................................................................................................ 9
Configuring the Connection from Gateway System to Backend System ...................................................... 12
Creating a Gateway Service (in the Gateway System) ................................................................................. 13 Creating the data model ............................................................................................................................................. 13
Creating the Consumption Model ............................................................................................................................... 18
Assign System Alias to OData Service ...................................................................................................................... 21
Testing the Gateway Service ............................................................................................................................ 22
Creating the Android Application ...................................................................................................................... 23
Create a new application in Android ............................................................................................................. 23
UI Design and Code ...................................................................................................................................... 25
Related Content ................................................................................................................................................ 35
This document guides you through the process of creating a mobile client for a decision service implemented in BRFplus using SAP NetWeaver Gateway Service.
Business Scenario
We would like to implement a simple Body-Mass Index (BMI) Calculator. The BMI is a common measure used to make a first estimate of whether the relationship between a person‟s height and weight might indicate a medical risk for that person or not.
Background Information
Since we would like to expose our service outside the scope of an SAP system, we need to make our functionality accessible via the SAP NetWeaver Gateway Interface. There are several ways to create the interface but for this document we have used the RFC generator approach.
For more information on SAP NetWeaver Gateway and BRFplus, please refer to the following links:
SAP BRFplus Page on SCN
SAP NetWeaver Gateway Page on SCN.
SAP NetWeaver Gateway Developer Guide.
SAP NetWeaver Gateway How-To guides on SCN.
Prerequisites
The following prerequisites must be fulfilled to complete the steps in this guide:
Access to a NetWeaver system with sufficient authorizations to run the BRFplus workbench.
Access to a configured Gateway 2.0 system.
Knowledge about modeling decision service in BRFplus and using the API‟s.
Firefox web browser with REST add-on.
The following tools need to be installed for developing an Android application:
o Eclipse 3.6
o Android SDK Windows
Step-by-Step Procedure
The following steps guide you through the process of creating a Gateway service based on a decision service modeled in BRFplus and then consuming the service through a mobile application running on the Android platform.
Creating the Body-Mass Index decision service in BRFplus
The Body-Mass Index decision service uses the height and weight information to calculate a measure. The measure in turn is used to derive the category as for instance normal, underweight or obese etc. We will go over the rule creation very briefly as we assume the reader is already familiar with BRFplus modeling.
Step 1: Create an application BMI_SERVICE
In the BRFplus workbench, first create an application BMI_SERVICE as shown below:
3. BMI_RESULT (Text: Body Mass Index) is a structure with two components – MEASURE and
CATEGORY. MEASURE is a data element of type Number (Length: 5, Decimals: 2) and
CATEGORY is a data element of type Text (Length: 2). This is illustrated by the figure below –
Step 3: Once the data objects are created, the next step is to create the function BMI_SERVICE with HEIGHT and MASS as the context data objects and BMI_RESULT as the result data object as shown below:
Step 4: Create the ruleset BMI_RULES (Text: BMI Rules). The ruleset comprises 6 rules altogether which we will summarize in the following section. The first rule (1) determines the calculation schema based on the quantity units.
Executing a BRFplus Decision Service from an Android device
The decision table „Determination of Calculation Schema‟ is shown below –
The second rule (2) checks if the calculation schema is undefined. If it is, then a log message action is executed. The next rule (3) is an exit condition which stops rule processing if the calculation schema is undefined.
Executing a BRFplus Decision Service from an Android device
Once the decision service is modeled, the next step now is to create a remote-enabled function which will trigger the decision service processing. The remote-enabled function can be either hand-coded or automatically generated from the BRFplus workbench as described in the following section.
The following is an example of a remote-enabled function coded manually:
Executing a BRFplus Decision Service from an Android device
FUNCTION ZBMI_STRUCT_FUNC. *”---------------------------------------------------------------------- *”*”Local Interface: *” IMPORTING *” VALUE(HEIGHT) TYPE FDT_S_QUANTITY *” VALUE(WEIGHT) TYPE FDT_S_QUANTITY *” EXPORTING *” VALUE(BMI_RESULT) TYPE ZSBMI_RESULT *”---------------------------------------------------------------------- DATA: lo_fct TYPE REF TO if_fdt_function, ls_mass TYPE if_fdt_types=>element_quantity, ls_height TYPE if_fdt_types=>element_quantity, lo_context TYPE REF TO if_fdt_context, lo_result TYPE REF TO if_fdt_result, ls_bmi TYPE zsbmi_result, lt_msg TYPE if_fdt_types=>t_message,
Executing a BRFplus Decision Service from an Android device
In contrast to the manually coded function, the following steps illustrate how you can let the BRFplus workbench do all the work for you:
Provide the function group name, function name and check the Local Package checkbox. Then click on Generate button.
The remote-function module is now generated. We can view and execute the function module in SE37 transaction.
Configuring the Connection from Gateway System to Backend System
It is very likely that the BRFplus system and the Gateway system are not the same. In this case we have to configure or setup the RFC connection in the Gateway system. For a detailed description of how to create or
Executing a BRFplus Decision Service from an Android device
set up an RFC connection between two SAP systems, please follow the link: Generate/Change RFC Connections.
Creating a Gateway Service (in the Gateway System)
We have now provisioned our decision service and also set up the RFC connection to execute our remote function which will trigger the processing of the decision service. As before, we will provide the details of creating a Gateway service using RFC-enabled function module. All the necessary details can be obtained via the aforementioned documents. We will summarize the steps in short and focus on the important ingredients.
In order to create a gateway service, we have to first create a data model and then a consumption model on top of it.
Creating the data model
A data model is created to design and maintain the content of the service based on existing sources, such as Remote Function Call (RFC), Screen Scrapping and Business Object Repository (BOR).
1. Open transaction SE80 in the Gateway system.
2. Select „GW Data Model‟ from the drop down menu.
3. Write the name of the data model you want to create in the text box below the drop down box and
14. Generate the data model by clicking on the Generate icon. To make the data model persistent, you
need to generate it. There is no Save option for data models.
Creating the Consumption Model
A consumption model is created to expose the content to be consumed as an OData service adhering to REST based principles. Once a consumption model is created, the Gateway service is exposed via the ICF (Internet Communication Framework).
1. Select ‘GW Consumption Model’ from the drop down menu.
Executing a BRFplus Decision Service from an Android device
7. Copy the URL generated in the consumption model and paste in the URL field of Firefox REST client
for testing the service (described in Section 6).
Assign System Alias to OData Service
In order to consume the created service you need to assign system aliases to the OData service. To assign a system alias to the OData Service, proceed as follows:
1. Open transaction SPRO in the gateway system.
2. Open SAP Reference IMG SAP NetWeaver Gateway OData Channel Administration
General Settings
3. Click on Execute icon of Assign SAP System Aliases to OData Service.
4. In the new window click on icon New Entries.
Executing a BRFplus Decision Service from an Android device
5. In the Service Doc. Identifier column, enter the name of the consumption model. In the SAP System
Alias column, enter the Alias name and check the checkbox in the Default System column.
6. Click on SAVE icon.
7. On saving the Prompt for Customizing Request dialog appears. Select your request and click OK.
Testing the Gateway Service
Once the consumption model is created, we are now ready to test our new service. For the purpose of testing the correctness of our service, we have used the Firefox REST client. In order to test the service, open the REST client and copy and paste the service URL. You can then inspect the xml response to find out if the expected results were obtained.
Executing a BRFplus Decision Service from an Android device
BRFplus provides a flexible set of API‟s which can be easily wrapped over a Gateway service and consumed from devices and applications outside the SAP domain. This document covers a simple scenario of simulating a Body Mass Index decision service from an android device. The concepts can be easily extended to other complex decision service scenarios. A similar implementation can also be carried out for other devices like iPhone or iPad.
Executing a BRFplus Decision Service from an Android device
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 Oracle Corporation.
JavaScript is a registered trademark of Oracle Corporation, 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.