All product information in wiki.bizagi.com is only valid for Bizagi BPM Suite 9.1.X.
For newer Bizagi BPM Suite versions (10.X and up) please visit the User Guide.
 

How to integrate Bizagi with SAP by invoking BAPI wrappers

From Business Process Management, BPM and Workflow Automation Wiki | BizAgi BPMS

Jump to: navigation, search

<keywords content="keywords"> SAP, Netweaver, SAP R3, R3, SAP Netweaver, SAP transaction, record management, new record, flight, flight module, component library, flightbooking, flight booking, bapi, bapi wrapper, bapi wrappers, Bizagi SAP integration, Bizagi SAP </keywords>

Applies to ENTERPRISE .NET EDITION

Contents

How to integrate Bizagi with SAP by invocation of BAPI wrappers

In this article we will describe how to integrate Bizagi with SAP, by having a process in Bizagi invoke a BAPI wrapper function in SAP.
This is possible by developing a component in .Net that uses the SAP.Net connector, and then registering it in Bizagi Component library (available in the Enterprise .Net edition).

In this example, we will illustrate specifically a creation of a flight booking in SAP done from Bizagi with a component that requires programming.
The developed component in .Net consists of connecting to SAP and invoking the BAPI wrappers available in SAP to create the transaction and commit the information.
To illustrate this, the following diagram represents this how-to's architecture and workings:


The example shown in this how-to has been worked with the flight module available in SAP R/3, and with a Bizagi process called "BookFlight".
The functions in SAP used for this integration are the BAPI wrappers:

  • "BAPI_FLIGHT_GETLIST", which retrieves a list of available flights according to some filtering criteria.
  • "BAPI_FLBOOKING_CREATEFROMDATA", which creates a new flight booking.
  • "BAPI_TRANSACTION_COMMIT", which commits the transaction.


In brief, the "BookFlight" process works as described:

  1. A user creates a new case for a travel request, in which he/she inputs mainly: departure city, arrival city, and a date range possible for the requested flight date.
  2. A list of available flights is obtained from SAP.
  3. The petitioner chooses a specific flight from the available flights and submits this request with complementary information such as: the passenger's name, and the desired flight class.
  4. When the request is approved by the approving user, then the flight booking is created in SAP and a notification will arrive via e-mail.




Hence, the steps involved to cover the integration as mentioned here involve first looking up SAP's functions import and export parameters (input and output), so that we acknowledge the data (and its structure) that is expected and that is received.
Then, developing a component in .Net which uses the SAP.Net connector.
Finally, we register that component and use it in Bizagi expressions.


You may download the project's database used in this example here.

Alert: This project was created with Bizagi Enterprise 9.1.6, and its backup contains the process implementation. To see this example working, you would still need to complete the next steps of this how-to.


Prerequisites

In order to accomplish this integration it is required to:

  • Have the functions in your SAP system that retrieve and creating data in SAP.
  • Download and install the "SAP.Net Connector" assemblies from SAP's official site. This connector allows a .Net project to access the SAP system and perform invocations of those BAPI wrappers.


Further information about the "SAP.Net Connector" can be found at the SAP connectors' link provided here with authorized access.



Looking up the functions and detail to invoke in SAP

Given that we are going to invoke already existing BAPI wrappers functions, we will look them up to obtain their definition and detail.

This includes getting to know the import/export and table parameters, and the metadata of the structures involved. In this particular case we will illustrate the configuration for the BAPI_FLBOOKING_CREATEFROMDATA BAPI wrapper. Therefore, we need to take a look and understand the structure expected in SAP to create a new flight booking.

In order to instantiate these objects in our .Net project, we can look up these functions' detail by using SAP's Netweaver Logon and input the transaction code "se37", which takes us to the management of functions.



In the image below, we see the display window for our BAPI_FLBOOKING_CREATEFROMDATA function and its import parameters.


The BAPISPONEW structure detail for our new booking-data information is:


This function's return handle tables as well. We will retrieve information from the RETURN table to acknowledge if the flight booking was created, and to notify our Bizagi user with SAP's reference number for the created record.


Similarly, we look up the BAPI_FLIGHT_GETLIST function that we will also invoke in SAP to previously get a list of available flights for the booking.

Creating the .Net component

For our SAP access component, we create a new project and ensure that the SAP.Net Connector assemblies are included as a reference. The SAP.Net Connector assemblies for its 3.0 version are: "sapnco.dll" and "sapnco_utils.dll", and are located in the path chosen for the SAP.Net Connector installation.


For this example, we created two classes to handle SAP Access as shown below. SAPController.cs is our entry point for our BookFlight process in Bizagi.
It has the two methods "GetFlights()" and "CreateBooking()", each one for the corresponding SAP function invocation.
It is coded as:


SAPAccess.cs has the connection settings and the implementation details. It is coded as:


Notice that the method setConnection() in SAPAccess.cs has the specific information of the installed SAP system. You will need to ensure that these values are set according to your SAP installation.
Notice too that the method CreateFromData_Booking() uses the BAPISPONEW structure's metadata and the RETURN table as looked up in SAP in the previous step.
Take into account that after invoking a function that creates new data in SAP, we need to call upon the BAPI_TRANSACTION_COMMIT function as well to persist the information. It is required also to end the current context (using RfcSessionManager.EndContext()).
For this example, a fixed customer (SCUSTOM) and agency (STRAVELAG) are used as input for SAP's functions.

Download this Visual Studio project here.
Remember that this project download does not contain the SAP.Net Connector assemblies (they are provided by SAP by using your SAP's installation authorized access).

Registering the component in Bizagi

Once the project in Visual Studio compiles with its output type set as "class library" (for our example the output component is "BizagiSAP.dll"), registering this "BizagiSAP.dll" component in our Bizagi project is done by including it in the Component Library option.

We include .dll files through the Component Library option found in Bizagi Studio as shown below:


We create a new component library and define its information:


We upload the dll file into this new component library:


Ensure you input the corresponding namespace for your assembly (as used in the .Net code):


For this specific how-to, take into account that it is required to register the SAP.Net Connector assemblies as well ("sapnco.dll" and "sapnco_utils.dll"). Therefore, we repeat these steps for the "sapnco.dll" and "sapnco_utils.dll" assemblies from SAP.
Your Bizagi project should have in the end the 3 component libraries used for the SAP connection.



Using the registered component and its methods in a rule

Methods in the registered component may now be used from within processes in our Bizagi project, by calling upon them from a Bizagi expression. In this example two expressions are created to make use of our component. One expression is set in the service task "Get available flights from SAP" to end up invoking our SAP's BAPI_FLIGHT_GETLIST function. The other expression is set in the service task "Book flight in SAP" to end up invoking our SAP's BAPI_FLBOOKING_CREATEFROMDATA function.

To illustrate this, the activity action at the onExit of the "Book flight in SAP" task is shown below:


The "create booking" expression module contains the following code which calls the target .Net method (in our entry point class SAPController.cs):


The main line containing the invocation code has:

<BookFlight.ResponseConfirmation> = BizagiSAP.SAPController.CreateBooking(airlineId,connectionId,
flightYear, flightMonth, flightDay,customerId, flightClass, agencyCode, passengerName);


Similarly, for the expression at the "onExit" of "Get available flights from SAP", the expression would include the corresponding function call:

responseArray = BizagiSAP.SAPController.GetFlights(<BookFlight.FlightRequest.ArrivalCity.Name>,
<BookFlight.FlightRequest.DepartureCity.Name>, date1.Year, date1.Month, date1.Day,
date2.Year, date2.Month, date2.Day, <BookFlight.FlightRequest.DateRange>);


Notice we have managed to use in Bizagi and the expression separate fields for the flight date's day, month and year. This is done to ensure that the DATE type information is sent as SAP expects it (that is, with 'yyyy-MM-dd' format).


At this point, integration through the component library is set to access SAP system from your Bizagi process!



Related Topics

<comments/>