Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
vijay_g
Explorer
Hello Everyone,

SAP Business Application Programming Interface (BAPI) provides interface to access processes and data defined in SAP Business Application System such as SAP E-Commerce for SAP R/3 or SAP S/4HANA system.

BAPIs are implemented generally as RFC enabled function modules. It also acts as function to a business object defined in BOR(Business Object Library). BAPIs provide stable and standard interfaces to interact with SAP back-end system.

Today we will demonstrate one example to showcase how to make a call to BAPI interface from SAP Intelligent RPA.

The basic technology we use to connect to SAP back-end system is SAP ActiveX component. Here is a comprehensive list of ActiveX control that can be used. Today we will demonstrate the "Function Control" specifically.

The example below is about getting the user information from the SAP system by passing the user-id as a parameter. We will create the activeX object and pass user-name as a parameter to the function. We will then make a call to BAPI, extract the export values and log the information to the log.

  • Open the "SAP Intelligent Robotic Process Automation Desktop" from your windows system.

  • Create an empty Project by going to File -> New Project. Enter the details about your project.

  • Go to Editor View (JavaScript) and open the Test JavaScript library.

  • Remove all the code and copy paste the code below to this file.


/** main process stop handler */
GLOBAL.events.QUIT.on(function (ev) {
});

/** main process start handler */
GLOBAL.events.START.on(function (ev) {
systray.addMenu('', 'evTestBAPIActiveX', 'Test BAPI connectivity', '', function (ev) {
bapi();
});
});

/** This method is used internally to initialize the BAPI object. */
function getBAPI(){
var BAPI = new ActiveXObject("SAP.Functions");
var Connection = BAPI.Connection;
Connection.ApplicationServer = "<IP/name of app server>"; //Change this
Connection.SystemNumber = 'xx'; //Change this
Connection.Client = "xxxx"; //Change this
Connection.User = "xxxx"; //Change this
Connection.Password = "xxxx"; //Change this
Connection.logon(0, true);
return BAPI;
}

/** This method gets called when systray menu is selected. */
function bapi() {
var BAPI = getBAPI();
var UserInfo = BAPI.Add("BAPI_USER_GET_DETAIL");
var UserImport = UserInfo.exports("USERNAME");
UserImport.value = "xxxx"; //Change this
UserInfo.Call();
var Address = UserInfo.imports("ADDRESS");
ctx.log('status= ' + Address("FIRSTNAME") + " " + Address("LASTNAME"));
}


  • Replace the system details and credentials accordingly. Look for comments "//Change this".

  • Now run the scenario from desktop studio in debug mode. You will see agent coming up in sys tray. Select the menu "Test BAPI connectivity" and the bot will execute.

  • You will see a log in console about the users first name and last name.


Note: The first call to the BAPI will take some time, but 2nd call onward performance will be much better.

Follow SAP Intelligent RPA on Twitter and LinkedIn.

Share your feedback and happy bot building!

51 Comments