使用 SAP BAPI 将数据写入 SAP 的示例 package

使用 SAP BAPI package,构建将数据写入 SAP 数据库的 bot

先决条件

Download the SAP Java connector and dynamic library files (.dll file for Windows automation and .dylib file for macOS automation) from the SAP portal.

在本教程中,您将构建一个从 SAP 演示航班数据应用程序调用 BAPI_FLCUST_CREATEFROMDATA 的 bot。 您将使用 CUSTOMER_DATA 导入参数将客户数据传递给 BAPI。 执行时,bot 会在 SAP 数据库中创建一个新的客户记录,并显示 BAPI 返回的客户编号。

此教程演示了如何执行以下操作:
  • 使用“获取结构”命令设置导入参数的值。
  • 在 SAP 表中创建一个新记录。
  • 接收来自 BAPI 的响应。

过程

  1. 创建名为 SAP-BAPI-CreateNewFlightCustomerbot
    1. 登录到 Control Room
    2. 在左侧窗格中,单击自动化
    3. 单击创建机器人图标。
    4. 名称字段中,输入 SAP-BAPI-CreateNewFlightCustomer,然后单击创建和编辑
  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/DYLIB dependency, specify the path to the dynamic library file.
      .dll for Windows automation and .dylib for macOS automation.
    3. Choose Custom Application Server as Connection Type.
    4. In Application server host name, specify the host name of the SAP application server.
      注: 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 username.
    11. In Password, enter your password.
    12. Run the bot to test the connection.
      If you specify the correct connection properties, the bot executes successfully.
  3. 要创建一个函数,请添加 SAP BAPI > 创建函数 操作。
    1. 函数别名中,输入 createNewFlightCustomer
    2. BAPI 名称中,输入 BAPI_FLCUST_CREATEFROMDATA
  4. 因为客户数据参数的类型是结构,所以会获取导入参数的结构并将其赋值给别名。 要做到这一点,请添加SAP BAPI > 获取结构操作。
    1. 函数别名中,输入 createNewFlightCustomer
    2. 结构名称中,输入 CUSTOMER_DATA
    3. 要将检索到的结构存储为别名,请单击目标中的别名选项卡。
    4. 创建结构别名中,输入 CustomerData
      您将使用别名来设置检索到的结构中导入字段的值。
  5. 要设置 CUSTNAME 字段的值,请添加SAP BAPI > 设置字段值操作。
    1. 函数别名 中,输入 createNewFlightCustomer
    2. 来源中,单击结构选项卡。
    3. 结构别名中,输入 CustomerData
    4. 字段名称中,输入 CUSTNAME
    5. 字段值中,输入 John Doe
  6. 重复步骤 5,为以下每个字段添加和配置设置字段值操作:
    字段名称 字段值
    街道 testStreet
    邮政编码 101001
    城市 testCity
    计数器 美国
    计数器 00000000
    电子邮件 test@example.com
    CUSTTYPE P
  7. 要执行 BAPI_FLCUST_CREATEFROMDATA,请添加SAP BAPI > 运行函数操作。
    1. 函数别名中,输入 createNewFlightCustomer
    注: 如果您希望 BAPI_FLCUST_CREATEFROMDATA 将数据写入 SAP 数据库,必须选择结束序列提交事务选项。 如果选择结束序列选项,请确保在创建函数操作中选择开始序列选项。

    本教程提供的示例 bot 旨在演示在使用 SAP BAPI package 时 Create() BAPI 的工作方式。 它并非旨在修改数据库。

    创建新的客户记录后,BAPI 会分配并返回一个客户编号。
  8. 要将此编号获取到变量中,请添加SAP BAPI > 获取字段值操作。
    1. 函数别名 中,输入 createNewFlightCustomer
    2. 来源中,单击函数选项卡。
    3. 字段名称中输入客户编号
    4. 将结果保存到变量中,通过单击 (x) 并选择变量,来创建一个名为 strCustomerNumber 的变量。
  9. 要显示客户编号,请添加消息框操作。
    1. 输入要显示的消息中,选择 strCustomerNumber 变量。
  10. 保存并运行 bot