使用 SAP BAPI 将数据写入 SAP 的示例 package
- Updated: 2022/09/21
使用 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 的响应。
过程
-
创建名为 SAP-BAPI-CreateNewFlightCustomer 的 bot。
- 登录到 Control Room。
- 在左侧窗格中,单击自动化。
- 单击创建机器人图标。
- 在名称字段中,输入 SAP-BAPI-CreateNewFlightCustomer,然后单击创建和编辑。
-
To connect the bot to your SAP system, from the
Actions panel, find SAP BAPI > Connect action and add it to the Bot editor.
- In JCo: SAP Java Connector package, specify the path to the Java connector .jar file.
-
In JCo DLL/DYLIB dependency,
specify the path to the dynamic library file.
.dll for Windows automation and .dylib for macOS automation.
- Choose Custom Application Server as Connection Type.
-
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.
- In System number, enter the instance number.
- In SAP instance system ID, enter the system ID.
- In Client number, enter the client number.
- In Logon language code, enter EN or the language specific to your system.
- In Router string, enter the SAP router string.
- In Username, enter your SAP username.
- In Password, enter your password.
-
Run the bot to test the connection.
If you specify the correct connection properties, the bot executes successfully.
-
要创建一个函数,请添加 SAP BAPI > 创建函数 操作。
- 在函数别名中,输入 createNewFlightCustomer。
- 在 BAPI 名称中,输入 BAPI_FLCUST_CREATEFROMDATA。
-
因为客户数据参数的类型是结构,所以会获取导入参数的结构并将其赋值给别名。 要做到这一点,请添加SAP BAPI > 获取结构操作。
- 在函数别名中,输入 createNewFlightCustomer。
- 在结构名称中,输入 CUSTOMER_DATA。
- 要将检索到的结构存储为别名,请单击目标中的别名选项卡。
-
在创建结构别名中,输入 CustomerData。
您将使用别名来设置检索到的结构中导入字段的值。
-
要设置 CUSTNAME 字段的值,请添加SAP BAPI > 设置字段值操作。
- 在 函数别名 中,输入 createNewFlightCustomer。
- 在来源中,单击结构选项卡。
- 在结构别名中,输入 CustomerData。
- 在字段名称中,输入 CUSTNAME。
- 在字段值中,输入 John Doe。
-
重复步骤 5,为以下每个字段添加和配置设置字段值操作:
字段名称 字段值 街道 testStreet 邮政编码 101001 城市 testCity 计数器 美国 计数器 00000000 电子邮件 test@example.com CUSTTYPE P -
要执行 BAPI_FLCUST_CREATEFROMDATA,请添加SAP BAPI > 运行函数操作。
- 在函数别名中,输入 createNewFlightCustomer。
注: 如果您希望 BAPI_FLCUST_CREATEFROMDATA 将数据写入 SAP 数据库,必须选择结束序列和提交事务选项。 如果选择结束序列选项,请确保在创建函数操作中选择开始序列选项。本教程提供的示例 bot 旨在演示在使用 SAP BAPI package 时 Create() BAPI 的工作方式。 它并非旨在修改数据库。
创建新的客户记录后,BAPI 会分配并返回一个客户编号。 -
要将此编号获取到变量中,请添加SAP BAPI > 获取字段值操作。
- 在 函数别名 中,输入 createNewFlightCustomer。
- 在来源中,单击函数选项卡。
- 在字段名称中输入客户编号
- 在将结果保存到变量中,通过单击 (x) 并选择变量,来创建一个名为 strCustomerNumber 的变量。
-
要显示客户编号,请添加消息框操作。
- 在输入要显示的消息中,选择 strCustomerNumber 变量。
- 保存并运行 bot。