Example of using Get structure command from SAP BAPI package

Using the SAP BAPI package, build a bot that inputs a structure to get data.

Prerequisites

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

In this tutorial, you will build a bot that invokes BAPI_FLIGHT_GETLIST from the SAP demo Flight Data application. When executed, the bot calls the BAPI function by inputting an airline ID and destination details, gets a list of flights, and writes the response data to a CSV file.

You will use the following import parameters to limit your search:
  • AIRLINE: Use the parameter to pass the airline ID.
  • DESTINATION_FROM: Use the parameter to get the structure and pass the city name and airport ID.
The tutorial is intended to demonstrate how to perform the following actions:
  • Get the structure of an import parameter.
  • Set the values for the fields in the retrieved structure.
  • Get response data in a table based on the input data.

Procedure

  1. Create a Task Bot named SAP-BAPI-FlightListReport.
    1. Log in to Control Room.
    2. On the left pane, click Automation.
    3. Click the Create a bot icon.
    4. In the Name field, enter SAP-BAPI-FlightListReport, 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 getFlightListByAirline.
    2. In BAPI name, enter BAPI_FLIGHT_GETLIST.
  4. To filter the data by an airline name, add the SAP BAPI > Set field value action.
    1. In Function alias name, enter getFlightListByAirline.
    2. Click the Function tab.
    3. In Field name, enter AIRLINE as the input parameter name.
    4. In Field value, enter AZ.
  5. To limit the selection by the airport and the destination city, get the structure of the DESTINATION_FROM import parameter first, and then set values for the fields in the retrieved structure. To do this, add the SAP BAPI > Get structure action.
    1. In Function alias name, enter getFlightListByAirline.
    2. In Structure name, enter DESTINATION_FROM .
    3. To assign the retrieved structure to an alias, click the Alias tab in Destination, and enter destinationFrom in Create structure alias.
      You can now use the alias to set values for the fields in the retrieved structure.
  6. To set a value for the AIRPORT ID field in the DESTINATION_FROM parameter, add the SAP BAPI > Set field value action.
    1. In Function alias name, enter getFlightListByAirline.
    2. In Source, click the Structure tab.
    3. In Structure alias, enter destinationFrom.
    4. In Field name, enter AIRPORTID.
    5. In Field value, enter FCO.
  7. To set a value for the CITY field in the DESTINATION_FROM parameter, add the SAP BAPI > Set field value action.
    1. In Function alias name, enter getFlightListByAirline.
    2. In Source, click the Structure tab.
    3. In Structure alias, enter destinationFrom.
    4. In Field name, enter CITY.
    5. In Field value, enter ROME.
  8. To execute BAPI_FLIGHT_GETLIST, add the SAP BAPI > Run function action.
    1. In Function alias name, enter getFlightListByAirline.
  9. To get the filtered data from the FLIGHT_LIST table, add the SAP BAPI > Get table action.
    1. In Function alias name, enter getFlightListByAirline.
    2. In Table name, click the FLIGHT_LIST tab.
    3. In Destination, click Variable to store the retrieved table data in memory.
    4. In Save the outcome to a variable, create a variable named tblFlightList by clicking (x).
  10. To write the data from the retrieved table to a CSV file, add the Data Table > Write to file action.
    1. In Data table, select tblFlightList.
    2. In Enter file name, specify the path to the CSV file to which you want to write the data.
    3. Select Create folders/files if it doesn't exist.
    4. Click Overwrite existing file.
  11. Save and then run the bot.