42
SAP NetWeaver How-To Guide Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration Applicable Releases: SAP NetWeaver Process Integration 7.1 SAP NetWeaver Business Rules Management 7.2 Topic Area: SOA Middleware Capability: Service Bus Version 1.1 March 2010

Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

  • Upload
    others

  • View
    28

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

SAP NetWeaver

How-To Guide

Access SAP NetWeaver Business

Rules Management from SAP

NetWeaver Process Integration

Applicable Releases:

SAP NetWeaver Process Integration 7.1

SAP NetWeaver Business Rules Management 7.2

Topic Area:

SOA Middleware

Capability:

Service Bus

Version 1.1

March 2010

Page 2: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

© Copyright 2010 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, Outlook, and PowerPoint are

registered trademarks of Microsoft Corporation.

IBM, DB2, DB2 Universal Database, OS/2, Parallel

Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390,

OS/400, iSeries, pSeries, xSeries, zSeries, z/OS, AFP,

Intelligent Miner, WebSphere, Netfinity, Tivoli, Informix,

i5/OS, POWER, POWER5, OpenPower and PowerPC are

trademarks or registered trademarks of IBM Corporation.

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.

MaxDB is a trademark of MySQL AB, Sweden.

SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP

NetWeaver, 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 in several other countries all over the world.

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.

These materials are provided “as is” without a warranty of

any kind, either express or implied, including but not

limited to, the implied warranties of merchantability,

fitness for a particular purpose, or non-infringement.

SAP shall not be liable for damages of any kind including

without limitation direct, special, indirect, or consequential

damages that may result from the use of these materials.

SAP does not warrant the accuracy or completeness of the

information, text, graphics, links or other items contained

within these materials. SAP has no control over the

information that you may access through the use of hot

links contained in these materials and does not endorse

your use of third party web pages nor provide any warranty

whatsoever relating to third party web pages.

SAP NetWeaver “How-to” Guides are intended to simplify

the product implementation. While specific product

features and procedures typically are explained in a

practical business context, it is not implied that those

features and procedures are the only approach in solving a

specific business problem using SAP NetWeaver. Should

you wish to receive additional information, clarification or

support, please refer to SAP Consulting.

Any software coding and/or code lines / strings (“Code”)

included in this documentation are only examples and are

not intended to be used in a productive system

environment. The Code is only intended better explain and

visualize the syntax and phrasing rules of certain coding.

SAP does not warrant the correctness and completeness of

the Code given herein, and SAP shall not be liable for

errors or damages caused by the usage of the Code, except

if such damages were caused by SAP intentionally or

grossly negligent.

Disclaimer

Some components of this product are based on Java™. Any

code change in these components may cause unpredictable

and severe malfunctions and is therefore expressively

prohibited, as is any decompilation of these components.

Any Java™ Source Code delivered with this product is only

to be used by SAP’s Support Services and may not be

modified or altered in any way.

Page 3: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Document History

Document Version Description

1.10 Revision

1.00 First official release of this guide

Page 4: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Typographic Conventions

Type Style Description

Example Text Words or characters quoted

from the screen. These

include field names, screen

titles, pushbuttons labels,

menu names, menu paths,

and menu options.

Cross-references to other

documentation

Example text Emphasized words or

phrases in body text, graphic

titles, and table titles

Example text File and directory names and

their paths, messages,

names of variables and

parameters, source text, and

names of installation,

upgrade and database tools.

Example text User entry texts. These are

words or characters that you

enter in the system exactly as

they appear in the

documentation.

<Example

text>

Variable user entry. Angle

brackets indicate that you

replace these words and

characters with appropriate

entries to make entries in the

system.

EXAMPLE TEXT Keys on the keyboard, for

example, F2 or ENTER.

Icons

Icon Description

Caution

Note or Important

Example

Recommendation or Tip

Page 5: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Table of Contents

1. Business Scenario............................................................................................................... 1

2. Background Information ..................................................................................................... 1

3. Prerequisites ........................................................................................................................ 1

4. Step-by-Step Procedure ...................................................................................................... 2

4.1 Create an XSD in the ESR ........................................................................................... 2

4.2 Create a BRM Rule in NWDS ....................................................................................... 3

4.2.1 Create a BRM Project ...................................................................................... 3

4.2.2 Import the XSD into the Project ....................................................................... 6

4.2.3 Add the XSD Elements to the BRM Project ..................................................... 8

4.2.4 Create a Ruleset ............................................................................................ 10

4.2.5 Create a Decision Table ................................................................................ 11

4.2.6 Create the Rule .............................................................................................. 18

4.2.7 Create a Web Service from the Rule ............................................................. 20

4.2.8 Build the Project ............................................................................................. 21

4.2.9 Deploy the Project .......................................................................................... 23

4.3 Testing the Rule using WSNavigator ......................................................................... 24

4.3.1 Use SOAMANAGER to Retrieve the WSDL of the Rule ............................... 24

4.3.2 Test the Web Service in WSNavigator .......................................................... 26

4.4 Configure PI to use the Rule from BRM ..................................................................... 27

4.4.1 Configure SOAP Communication Channel .................................................... 27

4.5 Develop Message Mapping in the Enterprise Services Repository ........................... 28

4.5.1 Message Types Used for Mapping ................................................................ 28

4.5.2 Create the User-Function to Call the Rule Web Service ............................... 29

4.5.3 Construct the Message Mapping ................................................................... 31

4.5.4 Test the Message Mapping............................................................................ 31

5. Appendix ............................................................................................................................ 33

5.1 Appendix A: Code example of the user-defined function calling a BRM Ruleset

web service ................................................................................................................. 33

5.2 Appendix B: How to obtain the structure of the XML Message used to call the web

service. ....................................................................................................................... 34

Page 6: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 1

1. Business Scenario

SAP NetWeaver Business Rules Management (BRM) provides a powerful toolset covering all aspects

of rule handling in business applications. Message processing in SAP NetWeaver Process integration

(PI) can take advantage of those business rules in multiple ways.

2. Background Information

SAP NetWeaver PI can make use of rules in multiple ways:

Within routings, business rules may provide additional data in Extended Receiver

Determinations and Enhanced Interface Determinations

Within a mapping step, business rules information may enrich the original data providing lookup

and value mapping functionality

Within ccBPM, rules may also be used to enrich process data or to provide decision criteria for

conditions steps

This HowTo-Guide makes use of very simple message mapping scenario to highlight the steps that

are required to take advantage of SAP NetWeaver Business Rules Management in process

integration. The example provided here may also serve as role model for the usage of BRM in PI

routings and PI Integration Processes (ccBPM processes).

3. Prerequisites

This HowTo-Guide describes a scenario that has been implemented using a PI system version 7.1

EhP1 and a BRM system version 7.2.

Knowledge Required

Basic knowledge in rules modeling

Familiar with Business Rule Management System

Basic knowledge in PI 7.1

Familiar with Message Mapping in PI

Software Required

SAP NetWeaver Developer Studio 7.20, includes the Rules Composer perspective

SAP CE 7.20, and with it configured in the SAP NetWeaver Developer Studio

SAP PI 7.1 EhP1

Page 7: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 2

4. Step-by-Step Procedure

In this guide we will create a rule to determine customer discounts based on their customer number

and which region the order came from. Then, we will use this rule in our PI message mapping. The

message mapping can be used to determine the total discounted cost of the order, which can be sent

to a backend system for fulfillment.

The steps of the exercise are as follow: ...

1. Create an XSD which can be used by BRM to create the rules. The XSD is created by

designing a Message Type in PI’s Enterprise Service Repository (ESR).

2. Create a BRM rule using NWDS:

a. Create a BRM project.

b. Import the XSD created from the Message Type.

c. Create a decision table using the elements of the XSD.

d. Create a rule to use the decision table.

3. Create a web service from the rule.

4. Build and deploy the project to a CE 7.2 system.

5. Test the web service.

6. In PI’s Integration Directory, create a SOAP adapter to use the web service.

7. In PI’s ESR, create a Message Mapping and a user-define function to use the web service.

8. Test the Message Mapping.

4.1 Create an XSD in the ESR ...

1. Create a Message Type with the following elements:

Page 8: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 3

2. In the XSD tab of the Message Type, we can copy or export the XSD to a local file.

4.2 Create a BRM Rule in NWDS

Tip

From more information on BRM, please reference “Business Rules Management Tutorial Center” in SDN: http://www.sdn.sap.com/irj/sdn/nw-rules-management?rid=/webcontent/uuid/f066ec08-474b-2b10-4a97-b66d605de037

4.2.1 Create a BRM Project ...

1. Create a new project:

Page 9: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 4

2. Select Development Component:

3. Select the Rule Composer:

Page 10: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 5

4. Select MyComponent under LocalDevelopment:

5. Name the project: orderdiscount

Page 11: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 6

4.2.2 Import the XSD into the Project ...

1. Expand “src” in the project and right-click on “wsdl” and select “Import”:

2. Select “XSD” for the import and click “Next”:

Page 12: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 7

3. Click “Next”:

4. Enter the location of the XSD file and click “Finish”:

Page 13: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 8

5. The following screen should result:

4.2.3 Add the XSD Elements to the BRM Project ...

1. Add the XSD by double-click on “Project Resources”, select the “Alias” tab and click on “Add”

and select “XSD Element”:

Page 14: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 9

2. Select the imported XSD and click “Finish”:

3. Select the XSD elements which will be used in the development of rule or decision table.

Expand the XSD structure and check the following elements to be used:

OrderDiscount_MT/CustNo

OrderDiscount_MT/Region

OrderDiscount_MT/Discount = {double}

Note

Those elements designated as “= {something}”, such as Discount, is used for output. Those without it are used as input.

Page 15: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 10

4.2.4 Create a Ruleset S...

1. Create a ruleset by right-click on “Rules Modeling” and select “New Ruleset”:

2. Name the ruleset: OrderDiscountRule

Page 16: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 11

4.2.5 Create a Decision Table

The decision table will help to determine the customer discount. This is a very simple table, consisting

of using customer number and region as input, and providing the discount as the output. Create...

1. Create a new decision table by right-click on “Decision Table” and select “New Decision

Table…”:

2. Name the decision table: OrderDiscountTable:

Page 17: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 12

3. Select CustNo and Region as the conditions of the table. These are the inputs.

4. The following will result. Click “Next” to continue:

Page 18: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 13

5. Select the Action, which is “Discount”, for the decision table. This is the output.

6. The following screens will result:

Page 19: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 14

7. Enter value for the 1st customer by right-click on “Default Value” of the first column, CustNo, and

select “Add Condition Values…”:

8. Enter value for the 1st customer number:

Page 20: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 15

9. Enter values for Region of the 1st customer by repeating the above process in the 2

nd column:

10. Enter 3 values for Region: Americas, EMEA and APJ

11. The following table content should result:

Page 21: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 16

12. Create the rest of the customer values by right-click on the 1st customer and select “Add

Condition Values…”:

13. Add CustNo values for the rest of the customers:

Tip

The reason we go through this process of creating the 1st customer first, then creating

the remaining customers is that the template of the 1st customer will be use for all the

other customers, e.g. all the regions names will all be included.

Page 22: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 17

14. The following table entries will result:

15. Enter the Discount values as below:

Page 23: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 18

4.2.6 Create the Rule ...

1. Create a new Rule:

2. Name the new rule: OrderDiscountRule

Page 24: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 19

3. In the Rule development screen, click “+” under the “If” condition. Replace the left-hand side

with “Boolean.TRUE” by clicking on “Operation.isSuccessful” and selecting “Boolean.TRUE”.

Repeat the same for the right-hand side of the Equals.

4. Assign the Decision Table.

Click on the “+” under the “Then” clause, and select the Decision Table “OrderDiscountTable”:

Page 25: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 20

5. The following should result:

4.2.7 Create a Web Service from the Rule ...

1. Create the Web Service:

Page 26: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 21

2. Navigate through the following screens:

4.2.8 Build the Project ...

1. Build the project by right-click on the project, select:

Development Component Build

Page 27: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 22

2. Click “OK” to complete:

Page 28: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 23

4.2.9 Deploy the Project

1. Deploy the project by right-click on the project, select:

Development Component Deploy…

2. Click “OK” to complete:

Page 29: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 24

4.3 Testing the Rule using WSNavigator

4.3.1 Use SOAMANAGER to Retrieve the WSDL of the Rule ...

1. Go to NWA on the CE 7.20 system where the Rule has been deployed.

Select: SOA Management Application and Scenario Communication Single Service

Administration

2. Retrieve the WSDL, by:

a. Enter: “*discount*” in the Find field.

b. Click “Go”.

c. Select “OrderDiscountRulePortType”.

d. Click the tab “WSDLs”.

e. Obtain the displayed WSDL.

Page 30: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 25

3. The web service can be displayed in the browser using the WSDL URL:

Important

Copy the location URL value in the WSDL to a Notepad. The URL will be used in the SOAP communication channel configuration in PI.

Page 31: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 26

4.3.2 Test the Web Service in WSNavigator ...

1. Start WSNavigator and enter the WSDL URL obtained from the previous step and click “Next”:

2. Enter CustNo and Region values as test data:

Page 32: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 27

3. The Discount value will be returned:

...

4.4 Configure PI to use the Rule from BRM

Important

This section will require the target URL you saved from Section 4.3.1, step 3

4.4.1 Configure SOAP Communication Channel

In order for Message Mapping to access the web service of the BRM rule, we will need to configure a

SOAP receiver communication channel. In the communication channel configuration, the target URL

location of the web service must be specified. This URL should have already been obtained in

Section 4.3.1, step 3.

The communication channel configuration should look like the following:

Page 33: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 28

Tip

Remember the Business Component name and Channel name. These will be used by the Message Mapping program.

...

4.5 Develop Message Mapping in the Enterprise

Services Repository

4.5.1 Message Types Used for Mapping

1. To demonstrate the Message Mapping, two Message Types are created, as shown below:

Page 34: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 29

cust_no and region will be used to determine the values for discount and total_cost.

2. Select tab Signature and add a parameter of category Adapter, type SOAP to the list of

Parameters

4.5.2 Create the User-Function to Call the Rule Web Service

The following is user-function create to call the webservice: ...

Page 35: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 30

1. Input variables:

2. User-function code:

The complete source code is in Appendix A.

Page 36: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 31

Tip

Appendix B shows how the XML message used for calling the rule web service can be obtained.

4.5.3 Construct the Message Mapping

The message mapping pertaining to the user-function is shown below:

4.5.4 Test the Message Mapping S...

1. Select the SOAP Communication Channel to use for the web service call.

2. Enter the source XML values and execute:

Page 37: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 32

...

Page 38: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 33

5. Appendix

5.1 Appendix A: Code example of the user-defined

function calling a BRM Ruleset web service

public String calculateDiscount(String cust_no, String region, Channel

soapDiscount, Container container) throws StreamTransformationException{

SystemAccessor accessor = null;

String discount = "";

StringBuffer sb = new StringBuffer();

try{

// 1. Get a system accessor for the channel.

accessor = LookupService.getSystemAccessor(soapDiscount);

// 2. Build up request

InputStream reqStream;

String reqString ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>"

+ "<ns0:Request-demo.sap.com-orderdiscount-OrderDiscountRule-

OrderDiscountRule xmlns:ns0=\"http://www.sap.com\">"

+ "<ns1:OrderDiscount_MT xmlns:ns1=\"http://test.com/brm/test\">"

+ "<CustNo>"+cust_no+"</CustNo> <Region>"+region+"</Region>"

+ "<Discount>0</Discount> </ns1:OrderDiscount_MT>"

+ "</ns0:Request-demo.sap.com-orderdiscount-OrderDiscountRule-

OrderDiscountRule>";

reqStream = (InputStream) new

ByteArrayInputStream(reqString.getBytes());

XmlPayload reqPayload = LookupService.getXmlPayload(reqStream);

// 3. Call BRM

XmlPayload resPayload = (XmlPayload)accessor.call(reqPayload);

// 4. Parse result

byte[] b = new byte[4096];

for (int n; (n = resPayload.getContent().read(b)) != -1;) {

sb.append(new String(b, 0, n));

}

int i =sb.indexOf("<Discount>") + 10;

int j =sb.indexOf("</Discount>");

discount = sb.substring(i, j);

}

catch (Exception e) {

Page 39: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 34

// TODO Auto-generated catch block

e.printStackTrace();

}

finally {

// 5. Close the accessor in order to free resources.

if (accessor!=null) accessor.close();

}

return discount;

5.2 Appendix B: How to obtain the structure of the

XML Message used to call the web service.

One way to obtain a sample XML message used to call the web service in ESR is to import the WSDL

of the web service as an external definition. Then, create a temporary mapping using the external

definition. In the test mode of the mapping, we can display the XML source, which can be used in the

user-defined function.

Obtaining the WSDL

A WSDL may import other WSDLs. When this is the case, we want to get the WSDL which defines

the structure of the message. This may require us to traverse multiple imports of the WSDL, as in this

case, to obtain the WSDL to use for external definition.

Copy the source of the WSDL to a local file.

Page 40: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 35

Create the External Definition and import the WSDL:

Page 41: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

March 2010 36

Create a temporary Message Mapping using the External Definition: Drag the External Definition to the source of the Message Mapping tool and select the request message.

Go to the test tab to obtain the source XML:

This is the XML message to be used with the web service.

Page 42: Access SAP NetWeaver Business Rules Management from SAP ...€¦ · Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March 2010 2 4. Step-by-Step

www.sdn.sap.com/irj/sdn/howtoguides