Example of writing data to SAP using SAP BAPI package

Using the SAP BAPI package, build a bot that writes data to the SAP database.

Prerequisites

Download the SAP Java connector and DLL from the SAP website.

In this tutorial, you will build a bot that invokes BAPI_FLCUST_CREATEFROMDATA from the SAP demo Flight Data application. You will use the CUSTOMER_DATA import parameter to pass the customer data to the BAPI. When executed, the bot creates a new customer record in SAP database and displays the customer number returned by the BAPI.

The tutorial demonstrates how to perform the following actions:
  • Use the Get structure command to set values for the import parameters.
  • Create a new record in an SAP table.
  • Receive a response from a BAPI.

Procedure

  1. Create a bot named SAP-BAPI-CreateNewFlightCustomer.
    1. Log in to the Control Room.
    2. On the left pane, click Automation.
    3. Click the Create a bot icon.
    4. In the Name field, enter SAP-BAPI-CreateNewFlightCustomer, and click Create & Edit.
  2. To connect the bot to your SAP system, from the Actions panel, find SAP BAPI > Connect action and add it to the Bot editor.
    1. In JCo: SAP Java Connector package, specify the path to the Java connector .jar file.
    2. In JCo DLL dependency, specify the path to the DLL file.
    3. Choose Custom Application Server as Connection Type.
    4. In Application server host name, specify the host name of the SAP application server.
      Note: As a best practice, use the Credential Vault to specify sensitive information such as host name, user name, and password.
    5. In System number, enter the instance number.
    6. In SAP instance system ID, enter the system ID.
    7. In Client number, enter the client number.
    8. In Logon language code, enter EN or the language specific to your system.
    9. In Router string, enter the SAP router string.
    10. In Username, enter your SAP user name.
    11. In Password, enter your password.
    12. Run the bot to test the connection.
      If the specified connection properties are correct, the bot is executed successfully.
  3. To create a function, add the SAP BAPI > Create function action.
    1. In Function alias name, enter createNewFlightCustomer.
    2. In BAPI name, enter BAPI_FLCUST_CREATEFROMDATA.
  4. Because the CUSTOMER_DATA parameter is of the type structure, get the structure of the import parameter and assign it to an alias. To do this, add the SAP BAPI > Get structure action.
    1. In Function alias name, enter createNewFlightCustomer.
    2. In Structure name, enter CUSTOMER_DATA.
    3. To store the retrieved structure as an alias, click the Alias tab in Destination.
    4. In Create structure alias, enter CustomerData.
      You will use the alias to set values for the import field within the retrieved structure.
  5. To set the value for the CUSTNAME field, add the SAP BAPI > Set field value action.
    1. In Function alias name, enter createNewFlightCustomer.
    2. In Source, click the Structure tab.
    3. In Structure alias, enter CustomerData.
    4. In Field name, enter CUSTNAME.
    5. In Field value, enter John Doe.
  6. Repeat Step 5 to add and configure the Set field value action for each of the following fields:
    Field name Field value
    STREET testStreet
    POSTCODE 101001
    CITY testCity
    COUNTR US
    COUNTR 00000000
    EMAIL test@example.com
    CUSTTYPE P
  7. To execute BAPI_FLCUST_CREATEFROMDATA, add the SAP BAPI > Run function action.
    1. In Function alias name, enter createNewFlightCustomer.
    Note: If you want BAPI_FLCUST_CREATEFROMDATA to write the data to SAP database, you must select the End sequence and the Commit transaction options. If you select the End sequence option, ensure that you select the Begin sequence option in the Create function action.

    The sample bot created with the help of this tutorial is intended to demonstrate how the Create() BAPIs work when the SAP BAPI package is used. It is not intended to modify the database.

    The BAPI assigns and returns a customer number after a new customer record is created.
  8. To get the number into a variable, add the SAP BAPI > Get field value action.
    1. In Function alias name, enter createNewFlightCustomer.
    2. In Source, click the Function tab.
    3. In Field name, enter CUSTOMERNUMBER
    4. In Save the outcome to a variable, create a variable named strCustomerNumber by clicking (x) and select the variable.
  9. To display the customer number, add the Message Box action.
    1. In Enter the message to display, select the strCustomerNumber variable.
  10. Save and run the bot.