Anda di halaman 1dari 50

SAP Business One

B1if Training
Yatsea Li,
SAP Business One Solution Architect for APJ
Dec 2011

Creating new Web Services with B1if


INTE
RNA
L

B1if Training: Creating new Web Services with B1if


This document guides you through how to create a
new web service function with B1if, getting the
document list from SAP Business One by type,
status and sale employee. And how to consume the
B1if web service by DotNet
In addition, we can expose and wrap backend
function of SAP Business One with DI call, SAP
Business Suites with RFC call, JAVA function of
external JAVA lib, SQL call with JDBC etc as web
services and RESTful interface.
After this chapter, you should be able to:
Describe how to create Web Services with B1if
How to generate a scenario package for web services
How to add additional call to SAP Business One in the
process of scenario step
How to implement the XSL to transform the result into
the final response message
2011
How
to Alltest
Web Service hosted in B1iC
SAP AG.
rights the
reserved.

Internal

Agenda

Case Analysis
Get document
list by doc type,
status and sales
employee
SOAP request
and response
format

2011 SAP AG. All rights reserved.

Integration
Scenario
Package
Scenario Step
Inbound
Outbound
Processing

Test
Get all sales
order
Get all open
sales order
Get all open
sales order by
sales employee

Setup
Export package
from dev system
Deactivate the
package in
customer system
Import and
Activate package
in customer
system

Internal

Web Services as Synchronous Processing in B1if

INBOUND
OUTBOUND

PROCESSING

Inbound

Processing

2011 SAP AG. All rights reserved.

Internal

Creating a new Web Service in B1if:


Get the document list by doc type, status and owner from SAP Business One

Backend
B1if

3rd Party Application


e.g. DotNet App
Request to get the
doc list by doc
type, status and owner

Web Service Provider


Reque
st
Respons
e

Scenario Package: xxx.WSTest


Scenario Steps: xxx.GetDocList
Input Parameters: Doc Table Name, Status, and Owner
Processing: SQL Call via JDBC to retrieve the doc list
Output: A document list with given doc type, status and
owner

SAP Business One


Retrieving documents
list by doc type, status
and owner

Design Phrase - Exposing a scenario step in B1if as a web service method:


xxx.WSTest is designed as a web service with several service methods, e.g. GetDocList etc is one method
in this web service. Each service method is implemented as a scenario step in the scenario package.
The logic of the service call is implemented with an additional SQL call to SAP Business One to get
document list, add or update the document in the step flow.
Note: Calling B1DI, BAPI, RFC etc is also possible in the main flow of scenario step, so is multiple call.
Run-Time Phase Consuming the new web service method hosted by B1if :
The web service is hosted as an activated scenario package, responsible for receiving the SOAP Request
from external system and handing over to the target scenario step for process
The relevant scenario step(web service method) will be triggered with the given SOAP request payload,
retrieving the document list from SAP Business One with SQL call.
The web service scenario step sends back the SOAP Response to the external system.
2011 SAP AG. All rights reserved.

Internal

Inbound SOAP Request


<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<GetDocList>
<TableName>ORDR</TableName>
<DocStatus>O</DocStatus>
<userName>manager</userName>
</GetDocList>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Service Method:
GetDocList Get the document list by document type, status and owner
The service method is identified by the root tag of SOAP Request.
Inbound Parameter:
- TableName: Table name of the document. ORDR Sales Order, OINV A/R Invoices etc.
Since all marketing documents share the table structure but with different table names, it can be reused to get all kind of
marketing documents.

- DocStatus: O Open, C Closed, (empty string) All


- userName: The current login user in mobile solution

2011 SAP AG. All rights reserved.

Internal

Outbound SOAP Response


After the final transformation in atom0.xsl, the outbound message should be like this:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<GetDocsListResponse xmlns="http://tempuri.org/">
<GetDocListResult>
<row>
<DocEntry>1</DocEntry>
<CardCode>C20000</CardCode>
<CardName>Norm Thompson</CardName>
<DocTotal>14,310.00 $</DocTotal>
<DocDate>2006-01-10 00:00:00.0</DocDate>
</row>
</GetDocListResult>
</GetDocsListResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Output document header field:
1.DocEntry Document Entry
2.CardCode Bp Code
3.CardName Bp Name
4.DocTotal Document total amount, format as: number + currency
5.DocDate Posting Date
2011 SAP AG. All rights reserved.

Internal

Process: Retrieving the target doc list with SQL Call via
JDBC

Atom 1: SQL atom to retrieve the


document list (to be added)

Atom 0: Final XForm atom to transform


into outbound format(default step)

Atom 1 - sql Call: Retrieving the doc list with sql call via JDBC
SELECT DocEntry, CardCode, CardName, DocDate, DocTotal FROM ORDR
WHERE DocStatus = O
-Output fields of document: DocEntry, Bp Code, Bp Name, Posting Date, Total Amount.
-Table [ORDR] will be replaced with variable $TableName from inbound parameter
-DocStatus O will be replaced with variable $DocStatus from inbound parameter
Atom 0 Final: Final transformation
Always the default last step to transform the message into outbound format with atom0.xsl
(to be implemented with xml editor later)
2011 SAP AG. All rights reserved.

Internal

Agenda

Case Analysis
Get document
list by doc type,
status and sales
employee
SOAP request
and response

2011 SAP AG. All rights reserved.

Integration
Scenario
Package
Scenario Step
Inbound
Outbound
Processing

Test
Get all sales
order
Get all open
sales order
Get all open
sales order by
sales employee

Setup
Export package
from dev system
Deactivate the
package in
customer system
Import and
Activate package
in customer
system

Internal

Create a new Scenario Package


Path: Scenarios/Package Design

Click the new button to create a new


package

Enter WSTest as Scenario Package


Identifier

Choose No Authentication as
Authentication

Click Save

1 4

Note: Scenario Packages cant be modified in active mode, only in design mode.

2011 SAP AG. All rights reserved.

Internal

10

Scenario Step Design:


xxx.GetDocList
Path: Scenarios/Step Design

1
2

2011 SAP AG. All rights reserved.

Type GetDocList as Scenario Step


Identifier. Prefix will be automatically
added.

Choose the Scenario Package


Identifier as xxx.WSTest

Click Save Button

Click Inbound Button

Internal

11

Scenario Step Design:


xxx.GetDocList: Inbound (2/3)
Path: Scenarios/Step Design/Working Step/[Inbound]
Identification method and trigger
Identification method as root tag and identifier as root tag name. In our case, the SOAP
Request body should be like:
<SOAP:Body>
<GetDocList>
.
</GetDocList>
</SOAP:Body>
Root tag <GetDocList> in SOAP request will trigger the process of scenario step
xxx.GetDocList

2011 SAP AG. All rights reserved.

Internal

12

Scenario Step Design:


xxx.GetDocList: Inbound (1/3)
Path: Scenarios/Step Design/Working Step/[Inbound]

2
3
4
5

Click on Channel

Using the ellipsis button () select Web Service


Call as Inbound Type

Using the ellipsis button () select Synchronous as


Process Mode

Using the ellipsis button () select Call as Process


Trigger

Using the ellipsis button () select Root Tag as


Identification Method

Input GetDocList as Identifier

Click Save

Click Close

6
7

2011 SAP AG. All rights reserved.

Internal

13

Scenario Step Design:


xxx.GetDocList: Inbound (3/3)
Path: Scenarios/Step Design/Working Step/[Inbound]

Click on Retrieval

Click Save

Click Close

Retrieval as Handover, B1if will decide


how to retrieve the inbound message

2011 SAP AG. All rights reserved.

Internal

14

Scenario Step Design:


xxx.GetDocList: Outbound
Path: Scenarios/Step Design

Click Outbound Button

Choose Outbound Channel as n.a.

Click Save Button

Click Close Button

2
3
2011 SAP AG. All rights reserved.

Outbound is unnecessary for synchronous call

4
Internal

15

Scenario Step Design:


xxx.GetDocList: Processing(1/4)
Path: Scenarios/Step Design

Click Processing Button

1
By default all scenario steps have one
xform atom (called final) associated with
an xslt file for final transformation.

2011 SAP AG. All rights reserved.

Internal

16

Scenario Step Design:


xxx.GetDocList: Processing(2/4)
Path: Scenarios/Step Design/Working Step/[Processing]

Click on triangle icon to add a new atom

Select Call SQL as new Flow Atom

Click Add Button

Click Close

2
3

2011 SAP AG. All rights reserved.

Internal

17

Scenario Step Design:


xxx.GetDocList: Processing(3/4)
Path: Scenarios/Step Design/Working Step/[Processing]

2011 SAP AG. All rights reserved.

Click on pen icon to edit sqlCall atom

Select #B1 System, based on User as


SysId

Enter #SELECT DocEntry, CardCode,


CardName, DocDate, DocTotal FROM
ORDR as SQL Statement

Click Save Button

Click Close Button

Note:
All the sales orders are retrieved in
one shot.
VariablesTableName and DocStatus
will be introduced later, to support
dynamically retrieving the document
list by document type ,status, and its
owner
Internal

18

Scenario Step Design:


xxx.GetDocList: Processing(4/4)
Path: Scenarios/Step Design/Working Step/[Processing]
After the configuration the Processing
diagram should be showing a green light
icon at the left and top of sqlCall atoms.
The next step is to modify the XSLT file of
the Final atom using your preferred XML
Editor.
In order to have access to the XSLT file,
WebDAV should be enabled as full. Refer
to B1if Installation slides for instruction.

2011 SAP AG. All rights reserved.

Internal

19

XMLSpy project
Open the project with XMLSpy

Well implement the final transformation of sql call result in atom0.xsl

2011 SAP AG. All rights reserved.

Internal

20

Edit atom0.xsl (Final) to transform the sql call result into


the target format
<xsl:template name="transform">
<GetDocsListResponse xmlns="http://tempuri.org/">
<GetDocListResult>
<xsl:for-each select="/vpf:Msg/vpf:Body/vpf:Payload[./@id=&apos;atom1&apos;]/jdbc:ResultSet/jdbc:Row">
<row>
<DocEntry>
<xsl:value-of select="./jdbc:DocEntry"/>
Transform the sql call result of
</DocEntry>
atom1 into the target format. It
<CardCode>
<xsl:value-of select="./jdbc:CardCode"/>
depends on the atom id of sql Call
</CardCode>
<CardName>
<xsl:value-of select="./jdbc:CardName"/>
</CardName>
<DocTotal>
<xsl:value-of select="./jdbc:DocTotal"/>
</DocTotal>
<DocDate>
<xsl:value-of select="./jdbc:DocDate"/>
</DocDate>
</row>
</xsl:for-each>
</GetDocListResult>
</GetDocsListResponse>
</xsl:template>

2011 SAP AG. All rights reserved.

Internal

21

Agenda

Overview

Case Analysis

Web Services in
B1if
Mobile Solution
Architecture
Procedure to
extend

2011 SAP AG. All rights reserved.

Get document
list by doc type,
status and sales
employee

Integration
Scenario
Package
Scenario Step
Inbound
Outbound
Processing

Test
Get all sales
order
Get all open
sales order
Get all open
sales order by
sales employee

Setup
Export package
from dev system
Deactivate the
package in
customer system
Import and
Activate package
in customer
system

Internal

22

Create and upload a xml file for test inbound message


with root tag <GetDocList>
1

Create an XML file with content below for test inbound message:
<?xml version="1.0" encoding="UTF-8"?>
<GetDocList>
</GetDocList>

Save the file as test_in_msg.xml

Open B1iP Control Center from path: Integration Framework for SAP Business One => Control Center

Upload to BizStore with Control Center from path: Maintenance/BizStore Upload


Select the test_in_msg.xml saved above.
Choose BizStore-URI as
/com.sap.b1i.vplatform.scenarios.design/vBIU.xxx.GetDocList/test_in_msg.xml(unified)
Click Submit button

2011 SAP AG. All rights reserved.

Internal

23

Debugging and Test


Path: Scenarios/Step Design/

Choose xxx.GetDocList as Scenario


Step Identifier

Click Processing Button

2011 SAP AG. All rights reserved.

Internal

24

Debugging and Test


Path: Scenarios/Step Design/Working Step/[Processing]

2011 SAP AG. All rights reserved.

Click Test Button

Choose 001sap0003 WSforMobile as


Test Sender System

Choose <Target B1 company> as


Test user based B1

Choose test_in_msg.xml as InboundMessage

Click Save Button

Click Run Button

3
4

Click Debug Button

Click Result Button

Internal

25

Step 1: Inbound

2011 SAP AG. All rights reserved.

Internal

26

Step 2: Processing Atom1 (sqlCall)


Retrieving the doc list with JDBC call

2011 SAP AG. All rights reserved.

Internal

27

Step 3: Processing Atom0 (Final Transformaiton)


Transforming the sql call result in to final outbound format

2011 SAP AG. All rights reserved.

Internal

28

Step 4: Outbound Result

2011 SAP AG. All rights reserved.

Internal

29

Agenda

Overview

Case Analysis

Web Services in
B1if
Mobile Solution
Architecture
Procedure to
extend

2011 SAP AG. All rights reserved.

Get document
list by doc type,
status and sales
employee

Integration
Scenario
Package
Scenario Step
Inbound
Outbound
Processing

Test
Get all sales
order
Get all open
sales order
Get all open
sales order by
sales employee

Setup
Export package
from dev system
Deactivate the
package in
customer system
Import and
Activate package
in customer
system

Internal

30

Add Inbound Variables TableName and DocStatus in


sqlCall
Path: Scenarios/Step Design

Choose xxx.GetDocList as Scenario


Step Identifier

Click Processing Button

2
Note:
B1if support both global and local variables, retrieving the parameter from inbound message. Making
the scenario more flexible and reusable.
We are going to create 3 local variables for Atom 1(sqlCall)
-TableName: the table name of document, e.g. ORDR - sales order, OINV - A/R Invoice etc
-DocStatus: the status of document, e.g. O Open, C Closed, (empty) - All

2011 SAP AG. All rights reserved.

Internal

31

Add Local Variables for sqlCall:


Variable#1 - TableName
Path: Scenarios/Step Design/Working Step/[Processing]

Click the pen icon to edit the sqlCall


atom

Click Lcl. Vars button in edit SQL


CALL window

Click Add button to add a new


variable

Enter TableName as variable name

Click Select button

Enter $msg/*/TableName as Xpath for


variable TableName

Click Save button

3
4
2

6
7

Inbound Parameter - Table Name of Document


- Retrieving from inbound request message
- Xpath: $msg/*/TableName
2011 SAP AG. All rights reserved.

Internal

32

Add Local Variables for sqlCall:


Variable#2 - DocStatus

2011 SAP AG. All rights reserved.

Click Add Button to add a new variable

Enter DocStatus as variable name

Click Select button

Enter $msg/*/DocStatus as Xpath for variable


DocStatus

Click Save button

Click Close button

Click Close button

Inbound Parameter - DocStatus (Document Status)


- Retrieving from inbound request message
- XPath: $msg/*/DocStatus

6
Internal

33

Using variables in sqlCall:


Replacing the hardcode ORDR and Open status
Path: Scenarios/Step Design/Working Step/[Processing]

Enter #SELECT DocEntry, CardCode,


CardName, DocDate, DocTotal FROM
$TableName WHERE DocStatus =
$DocStatus OR $DocStatus = as
SQL Statement

Click Save button

Click Close button

SQL Statement with variable:


#SELECT DocEntry, CardCode, CardName, DocDate, DocTotal FROM $TableName WHERE DocStatus =
'$DocStatus' OR '$DocStatus' = ''
Note: it should be $DocStatus with single quotes, not $DocStatus
If $DocStatus is empty, all Sales Orders will be retrived.
Important Note: Replace all signs in the SQL query after copying it from here, the signs are different.
2011 SAP AG. All rights reserved.

Internal

34

Modify the test inbound request message:


Add TableName and DocStatus
Target file:
http://<B1if_Server>:8080/B1iXcellerator/exec/dummy/com.sap.b1i.vplatform.scenarios.design/vBIU.xxx.GetDocList/test_in_msg.xml
You can edit the test inbound message uploaded in slide 29 with your preferred XML editor supporting WebDAV.
To Do:
-Add TableName as ORDR (Sales Order)
-Add DocStatus as O (Open)
-Save the test_in_msg.xml
Content of test_in_msg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<GetDocList xmlns:bfa="urn:com.sap.b1i.bizprocessor:bizatoms">
<TableName>ORDR</TableName>
<DocStatus>O</DocStatus>
</GetDocList>

2011 SAP AG. All rights reserved.

Internal

35

Debug and Test: Get all the open sales orders


Inbound => Run => Debug => Result
Path: Scenarios/Step Design/Working Step/[Processing]
1

2011 SAP AG. All rights reserved.

All the open sales orders

Internal

36

Agenda

Overview

Case Analysis

Web Services in
B1if
Mobile Solution
Architecture
Procedure to
extend

2011 SAP AG. All rights reserved.

Get document
list by doc type,
status and sales
employee

Integration
Scenario
Package
Scenario Step
Inbound
Outbound
Processing

Test
Get all sales
order
Get all open
sales order
Get all open
sales order by
sales employee

Setup
Export package
from dev system
Deactivate the
package in
customer system
Import and
Activate package
in customer
system

Internal

37

Access Control: Filter the document by current logon user


as sales employee

Business Requirement:
Access control to sales marketing document s by owner. Mostly, the sale employee s are only allowed to view their
own documents.
Solution:
Filter the document list by sales employee binding to SAP Business One user in Employee master Data

2011 SAP AG. All rights reserved.

Internal

38

Using variables in sqlCall:


Filter the document by current logon user as sales employee
Path: Scenarios/Step Design/Working Step/[Processing]

Click pen icon to edit sqlCall atom

Enter SQL Statement in the note below

Click Save Button

Click Close Button

3
SQL Statement with variable:
#SELECT DocEntry, CardCode, CardName, DocDate, DocTotal FROM $TableName T0
INNER JOIN OHEM T1 ON T0.SlpCode = T1.salesPrSon
INNER JOIN OUSR T2 ON T1.userId = T2.USERID
WHERE (DocStatus = 'O' OR '$DocStatus' = '')
AND T2.USER_CODE = '$Login'
Note:
1.It should be $DocStatus with semi-quote comma, not $DocStatus
2.$Login is a default variable defined in sap.B1Mobile as the current login use. XPath: $msg/*/userName

2011 SAP AG. All rights reserved.

Internal

39

Modify the test inbound request message:


Add userName as the login user in Mobile
Target file:
http://<B1if_Server>:8080/B1iXcellerator/exec/dummy/com.sap.b1i.vplatform.scenarios.design/vBIU.xxx.GetDocList/test_in_msg.xml
The test inbound message uploaded in page 29, you can edit it with your preferred XML editor supporting WebDAV
To Do:
-Add userName for the login user
-Save the test_in_msg.xml
Content of test_in_msg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<GetDocList xmlns:bfa="urn:com.sap.b1i.bizprocessor:bizatoms" xmlns="http://tempuri.org/">
<TableName>ORDR</TableName>
<DocStatus>O</DocStatus>
<userName>manager</userName>
</GetDocList>

2011 SAP AG. All rights reserved.

Internal

40

Debug and Test All open sales order for manager


Inbound=>Run=>Debug=>Result
Path: Scenarios/Step Design/Working Step/[Processing]
1

All the open sales orders for manager


2011 SAP AG. All rights reserved.

Internal

41

Activate the scenario for run-time


Path: Scenarios/Control

Check the check box of sap.B1Mobile to


activate it

Click Activate button

2011 SAP AG. All rights reserved.

Internal

42

Agenda

Overview

Case Analysis

Web Services in
B1if
Mobile Solution
Architecture
Procedure to
extend

2011 SAP AG. All rights reserved.

Get document
list by doc type,
status and sales
employee

Integration
Scenario
Package
Scenario Step
Inbound
Outbound
Processing

Test
Get all sales
order
Get all open
sales order
Get all open
sales order by
sales employee

Setup
Export package
from dev system
Deactivate the
package in
customer system
Import and
Activate package
in customer
system

Internal

43

Export the Package from development system


Path: Scenarios/Export

Choose sap.B1Mobile as Scenario


Package Identifier

Check the check box to Add test


messages

Click the button Package Export

1
2
3

Note: Export the package and save it as Zip file from Development System

2011 SAP AG. All rights reserved.

Internal

44

Deactivate sap.B1Mobile in Customer System


Path: Scenarios/Control

Uncheck sap.B1Mobile package to


deactivate

1
Note:
Scenario Package cant be modified in active mode, only can be modified in design mode.

2011 SAP AG. All rights reserved.

Internal

45

Import the updated package into customer system


Path: Scenarios/Import

2011 SAP AG. All rights reserved.

Browse the sap.B1Mobile.zip


package copied from dev system

Click Submit button

Internal

46

Activate the package in customer system for run-time


Path: Scenarios/Control

Check the check box of sap.B1Mobile to


activate it

Click Activate button

2011 SAP AG. All rights reserved.

Internal

47

XSD and WSDL generation


Path: Scenarios/Setup

Choose the target Scenario Package


Identifier as sap.B1Mobile

Click Tools button

Choose Document as XSD Generation

Click Select Button

Choose Document as WSDL


Generation

Click Select Button

5
6

2011 SAP AG. All rights reserved.

Internal

48

Test using with wfetch tool

Note: User and Password for B1 application can be seen because we didnt set Enforce Secure
Transport. sap.B1Mobile scenario is configured by default having SSL authentication as mandatory.
2011 SAP AG. All rights reserved.

Internal

49

Thank You!

For more information visit SDN at http://sdn.sap.com

Anda mungkin juga menyukai