从 Azure 逻辑应用连接到 SAP 系统Connect to SAP systems from Azure Logic Apps

Important

我们计划在 2020 年 2 月 29 日弃用早期版 SAP 应用程序服务器和 SAP 消息服务器的连接器。The earlier SAP Application Server and SAP Message Server connectors are scheduled for deprecation on February 29, 2020. 当前的 SAP 连接器具有以下特点:合并了这些以前的 SAP 连接器,使你不必更改连接类型;与以前的连接器完全兼容;提供许多其他的功能;继续使用 SAP .Net 连接器 (SAP NCo) 库。The current SAP connector consolidates these previous SAP connectors so that you don't have to change the connection type, is fully compatible with previous connectors, provides many additional capabilities, and continues to use the SAP .Net connector library (SAP NCo).

对于使用较旧连接器的逻辑应用,请在弃用日期之前迁移到最新连接器For logic apps that use the older connectors, please migrate to the latest connector before the deprecation date. 否则,这些逻辑应用会遇到执行故障,无法将消息发送到 SAP 系统。Otherwise, these logic apps will experience execution failures and won't be able to send messages to your SAP system.

本文介绍如何使用 SAP 连接器在逻辑应用内部访问本地 SAP 资源。This article shows how you can access your on-premises SAP resources from inside a logic app by using the SAP connector. 该连接器适用于 SAP 的经典版本,例如 R/3 和ECC 本地系统。The connector works with SAP's classic releases such as R/3 and ECC systems on-premises. 该连接器还支持与 SAP 的较新的基于 HANA 的 SAP 系统(例如 S/4 HANA)集成,不管它们是在本地还是在云中托管。The connector also enables integration with SAP's newer HANA-based SAP systems, such as S/4 HANA, whether they're hosted on-premises or in the cloud. SAP 连接器支持通过中间文档 (IDoc)、业务应用程序编程接口 (BAPI) 或远程函数调用 (RFC) 与基于 SAP NetWeaver 的系统相互进行消息或数据集成。The SAP connector supports message or data integration to and from SAP NetWeaver-based systems through Intermediate Document (IDoc), Business Application Programming Interface (BAPI), or Remote Function Call (RFC).

SAP 连接器使用 SAP .NET 连接器 (NCo) 库,并提供以下操作:The SAP connector uses the SAP .NET Connector (NCo) library and provides these actions:

  • 将消息发送到 SAP:在 SAP 系统中通过 tRFC 发送 IDoc、通过 RFC 调用 BAPI 函数,或调用 RFC/tRFC。Send message to SAP: Send IDoc over tRFC, call BAPI functions over RFC, or call RFC/tRFC in SAP systems.
  • 从 SAP 收到消息时:在 SAP 系统中通过 tRFC 接收 IDoc、通过 tRFC 调用 BAPI 函数,或调用 RFC/tRFC。When a message is received from SAP: Receive IDoc over tRFC, call BAPI functions over tRFC, or call RFC/tRFC in SAP systems.
  • 生成架构:为 IDoc、BAPI 或 RFC 生成 SAP 项目的架构。Generate schemas: Generate schemas for the SAP artifacts for IDoc, BAPI, or RFC.

对于这些操作,SAP 连接器支持通过用户名和密码进行基本身份验证。For these operations, the SAP connector supports basic authentication through usernames and passwords. 该连接器还支持安全网络通信 (SNC)The connector also supports Secure Network Communications (SNC). SNC 可用于 SAP NetWeaver 单一登录 (SSO) 或外部安全产品提供的其他安全功能。SNC can be used for SAP NetWeaver single sign-on (SSO) or for additional security capabilities provided by an external security product.

SAP 连接器通过本地数据网关与本地 SAP 系统集成。The SAP connector integrates with on-premises SAP systems through the on-premises data gateway. 例如,在“发送”方案中,如果将消息从逻辑应用发送到 SAP 系统,则数据网关将充当 RFC 客户端,将从逻辑应用收到的请求转发到 SAP。In send scenarios, for example, when a message is sent from a logic app to an SAP system, the data gateway acts as an RFC client and forwards the requests received from the logic app to SAP. 同理,在“接收”方案中,数据网关充当 RFC 服务器,从 SAP 接收请求并将其转发到逻辑应用。Likewise, in receive scenarios, the data gateway acts as an RFC server that receives requests from SAP and forwards them to the logic app.

本文介绍如何创建与 SAP 集成的示例逻辑应用,并阐述以前已介绍过的集成方案。This article shows how to create example logic apps that integrate with SAP while covering the previously described integration scenarios. 本文针对使用较旧 SAP 连接器的逻辑应用,介绍如何将逻辑应用迁移到最新的 SAP 连接器。For logic apps that use the older SAP connectors, this article shows how to migrate your logic apps to the latest SAP connector.

先决条件Prerequisites

若要按本文中的步骤操作,需准备好以下各项:To follow along with this article, you need these items:

  • Azure 订阅。An Azure subscription. 如果还没有 Azure 订阅,请注册一个 Azure 试用帐户If you don't have an Azure subscription yet, sign up for a trial Azure account.

  • 要从中访问 SAP 系统的逻辑应用,以及用于启动逻辑应用工作流的触发器。The logic app from where you want to access your SAP system and a trigger that starts your logic app's workflow. 如果你不熟悉逻辑应用,请参阅什么是 Azure 逻辑应用?快速入门:创建第一个逻辑应用If you're new to logic apps, see What is Azure Logic Apps? and Quickstart: Create your first logic app.

  • SAP 应用程序服务器SAP 消息服务器Your SAP application server or SAP message server.

  • 在任何本地计算机上下载并安装最新的本地数据网关Download and install the latest on-premises data gateway on any on-premises computer. 在继续操作之前,请确保在 Azure 门户中设置网关。Make sure you set up your gateway in the Azure portal before you continue. 网关有助于安全访问本地数据和资源。The gateway helps you securely access on-premises data and resources. 有关详细信息,请参阅为 Azure 逻辑应用安装本地数据网关For more information, see Install an on-premises data gateway for Azure Logic Apps.

  • 如果将 SNC 用于 SSO,请确保以映射到 SAP 用户的用户身份运行网关。If you use SNC with SSO, make sure the gateway is running as a user that's mapped against the SAP user. 若要更改默认帐户,请选择“更改帐户”并输入用户凭据。 To change the default account, select Change account, and enter the user credentials.

    更改网关帐户

  • 如果对外部安全产品启用 SNC,请在安装网关的同一台计算机上复制 SNC 库或文件。If you enable SNC with an external security product, copy the SNC library or files on the same machine where the gateway is installed. SNC 产品的部分示例包括 sapseculib、Kerberos 和 NTLM。Some examples of SNC products include sapseculib, Kerberos, and NTLM.

  • 在本地数据网关所在的计算机上下载并安装最新的 SAP 客户端库,该库当前是使用 .NET Framework 4.0(Windows 64 位 (x64))编译的用于 Microsoft .NET 3.0.22.0 的 SAP 连接器 (NCo 3.0)Download and install the latest SAP client library, which is currently SAP Connector (NCo 3.0) for Microsoft .NET 3.0.22.0 compiled with .NET Framework 4.0 - Windows 64-bit (x64), on the same computer as the on-premises data gateway. 安装此版本或更高版本的原因是:Install this version or later for these reasons:

    • 如果同时发送多个 IDoc 消息,早期的 SAP NCo 版本可能死锁。Earlier SAP NCo versions might become deadlocked when more than one IDoc message is sent at the same time. 这种状态会阻止向 SAP 目标发送所有后续消息,从而导致消息超时。This condition blocks all later messages that are sent to the SAP destination, which causes the messages to time out.
    • 本地数据网关只能在 64 位系统上运行。The on-premises data gateway runs only on 64-bit systems. 否则,会收到“错误的映像”错误,因为数据网关主机服务不支持 32 位程序集。Otherwise, you get a "bad image" error because the data gateway host service doesn't support 32-bit assemblies.
    • 数据网关主机服务和 Microsoft SAP 适配器使用 .NET Framework 4.5。Both the data gateway host service and the Microsoft SAP Adapter use .NET Framework 4.5. SAP NCo for .NET Framework 4.0 适用于使用 .NET 运行时 4.0 到 4.7.1 的进程。The SAP NCo for .NET Framework 4.0 works with processes that use .NET runtime 4.0 to 4.7.1. SAP NCo for .NET Framework 2.0 适用于使用 .NET 运行时 2.0 到 3.5 的进程,但不再适用于最新的本地数据网关。The SAP NCo for .NET Framework 2.0 works with processes that use .NET runtime 2.0 to 3.5, but no longer works with the latest on-premises data gateway.
  • 可以发送到 SAP 服务器的消息内容(例如示例 IDoc 文件)必须采用 XML 格式,并且包含要使用的 SAP 操作的命名空间。Message content you can send to your SAP server, such as a sample IDoc file, must be in XML format and include the namespace for the SAP action you want to use.

迁移到最新连接器Migrate to current connector

  1. 更新本地数据网关(如果尚未这样做),使自己的版本为最新版本。If you haven't done so already, update your on-premises data gateway so that you have the latest version. 有关详细信息,请参阅为 Azure 逻辑应用安装本地数据网关For more information, see Install an on-premises data gateway for Azure Logic Apps.

  2. 在使用较旧 SAP 连接器的逻辑应用中,删除“发送到 SAP”操作。 In the logic app that uses the older SAP connector, delete the Send to SAP action.

  3. 在最新的 SAP 连接器中,添加“将消息发送到 SAP”操作。 From the latest SAP connector, add the Send message to SAP action. 在使用此操作之前,必须重新创建到 SAP 系统的连接。Before you can use this action, recreate the connection to your SAP system.

  4. 完成后,保存逻辑应用。When you're done, save your logic app.

将消息发送到 SAPSend message to SAP

本示例使用可通过 HTTP 请求触发的逻辑应用。This example uses a logic app that you can trigger with an HTTP request. 该逻辑应用将一个 IDoc 发送到 SAP 服务器,并向调用逻辑应用的请求方返回响应。The logic app sends an IDoc to an SAP server and returns a response to the requestor that called the logic app.

添加 HTTP 请求触发器Add an HTTP Request trigger

在 Azure 逻辑应用中,每个逻辑应用都必须从触发器开始,该触发器在发生特定事件或特定条件得到满足的情况下触发。In Azure Logic Apps, every logic app must start with a trigger, which fires when a specific event happens or when a specific condition is met. 每当触发器触发时,逻辑应用引擎就会创建一个逻辑应用实例并开始运行应用的工作流。Each time the trigger fires, the Logic Apps engine creates a logic app instance and starts running your app's workflow.

本示例创建一个包含 Azure 中的终结点的逻辑应用,方便将 HTTP POST 请求发送到逻辑应用。In this example, you create a logic app with an endpoint in Azure so that you can send HTTP POST requests to your logic app. 当逻辑应用程序收到这些 HTTP 请求时,触发器将会触发,并运行工作流中的下一个步骤。When your logic app receives these HTTP requests, the trigger fires and runs the next step in your workflow.

  1. Azure 门户中创建一个空白的逻辑应用。此时会打开逻辑应用设计器。In the Azure portal, create a blank logic app, which opens the Logic App Designer.

  2. 在搜索框中,输入 http request 作为筛选器。In the search box, enter http request as your filter. 在触发器列表中,选择“当收到 HTTP 请求时”。 From the Triggers list, select When a HTTP request is received.

    添加 HTTP 请求触发器

  3. 现在请保存逻辑应用,以便为逻辑应用生成终结点 URL。Now save your logic app so that you can generate an endpoint URL for your logic app. 在设计器工具栏上选择“保存”。 On the designer toolbar, select Save.

    终结点 URL 现在会显示在触发器中,例如:The endpoint URL now appears in your trigger, for example:

    生成终结点的 URL

添加 SAP 操作Add an SAP action

在 Azure 逻辑应用中,操作是指工作流中紧跟在某个触发器或另一操作后面执行的一个步骤。In Azure Logic Apps, an action is a step in your workflow that follows a trigger or another action. 如果尚未将触发器添加到逻辑应用,但需要遵循本示例,请添加此部分所述的触发器If you haven't added a trigger to your logic app yet and want to follow this example, add the trigger described in this section.

  1. 在逻辑应用设计器中的触发器下,选择“新建步骤”。 In the Logic App Designer, under the trigger, select New step.

    向逻辑应用添加新步骤

  2. 在搜索框中,输入“sap”作为筛选器。In the search box, enter "sap" as your filter. 在“操作”列表中选择“将消息发送到 SAP”。 From the Actions list, select Send message to SAP.

    选择“向 SAP 发送消息”操作

    也可以选择“企业”选项卡,然后选择 SAP 操作。 Or, you can select the Enterprise tab, and select the SAP action.

    从“企业”选项卡选择“向 SAP 发送消息”操作

  3. 如果连接已存在,请继续下一步,以便可以设置 SAP 操作。If your connection already exists, continue with the next step so you can set up your SAP action. 但是,如果系统提示输入连接详细信息,请提供该信息,以便立即创建到本地 SAP 服务器的连接。However, if you're prompted for connection details, provide the information so that you can create a connection to your on-premises SAP server now.

    1. 为连接提供一个名称。Provide a name for the connection.

    2. 在“数据网关”部分的“订阅”下,首先选择在 Azure 门户中为网关安装创建的网关资源的 Azure 订阅。 In the Data Gateway section, under Subscription, first select the Azure subscription for the gateway resource that you created in the Azure portal for your gateway installation.

    3. 在“连接网关”下,选择网关资源。 Under Connection Gateway, select your gateway resource.

    4. 继续提供有关连接的信息。Continue providing information about the connection. 对于“登录类型”属性,请根据该属性是设置为“应用程序服务器”还是“组”来执行相关步骤: For the Logon Type property, follow the step based on whether the property is set to Application Server or Group:

      • 对于“应用程序服务器”,必须指定以下属性(通常显示为可选): For Application Server, these properties, which usually appear optional, are required:

      创建 SAP 应用程序服务器连接

      如果“登录类型”属性设置为“组”,则必须指定以下属性(通常显示为可选): If the Logon Type property is set to Group, these properties, which usually appear optional, are required:

      创建 SAP 消息服务器连接

      默认会使用强类型化通过针对架构执行 XML 验证来检查无效值。By default, strong typing is used to check for invalid values by performing XML validation against the schema. 此行为可帮助提前检测问题。This behavior can help you detect issues earlier. “安全类型化”选项用于实现后向兼容,它只会检查字符串长度。 The Safe Typing option is available for backward compatibility and only checks the string length. 详细了解安全类型化选项Learn more about the Safe Typing option.

    5. 完成后,选择“创建” 。When you're finished, select Create.

      逻辑应用会设置并测试连接,确保连接正常工作。Logic Apps sets up and tests your connection to make sure that the connection works properly.

  4. 现在,请找到并选择 SAP 服务器中的某个操作。Now find and select an action from your SAP server.

    1. 在“SAP 操作”框中,选择文件夹图标。 In the SAP Action box, select the folder icon. 在文件列表中,找到并选择要使用的 SAP 消息。From the file list, find and select the SAP message you want to use. 使用箭头可在列表中导航。To navigate the list, use the arrows.

      此示例选择了类型为“订单”的 IDoc。 This example selects an IDoc with the Orders type.

    找到并选择 IDoc 操作

    如果找不到所需的操作,可以手动输入路径,例如:If you can't find the action you want, you can manually enter a path, for example:

    手动提供 IDoc 操作的路径

    > [!TIP]
    > <span data-ttu-id="53fee-208">通过表达式编辑器提供“SAP 操作”的值。 </span><span class="sxs-lookup"><span data-stu-id="53fee-208">Provide the value for **SAP Action** through the expression editor.</span></span> <span data-ttu-id="53fee-209">这样,便可以对不同的消息类型使用相同的操作。</span><span class="sxs-lookup"><span data-stu-id="53fee-209">That way, you can use the same action for different message types.</span></span>
    

    有关 IDoc 操作的详细信息,请参阅 IDOC 操作的消息架构For more information about IDoc operations, see Message schemas for IDOC operations.

    1. 在“输入消息”框中单击,以显示动态内容列表。 Click inside the Input Message box so that the dynamic content list appears. 在该列表中的“收到 HTTP 请求时”下面,选择“正文”字段。 From that list, under When a HTTP request is received, select the Body field.

      此步骤包含来自 HTTP 请求触发器的正文内容,并将该输出发送到 SAP 服务器。This step includes the body content from your HTTP request trigger and sends that output to your SAP server.

      选择“正文”字段

      完成后,SAP 操作如以下示例所示:When you're finished, your SAP action looks like this example:

      完成 SAP 操作

  5. 保存逻辑应用。Save your logic app. 在设计器工具栏上选择“保存”。 On the designer toolbar, select Save.

添加 HTTP 响应操作Add an HTTP response action

现在,请将响应操作添加到逻辑应用的工作流,并包括来自 SAP 操作的输出。Now add a response action to your logic app's workflow and include the output from the SAP action. 这样,逻辑应用便可将来自 SAP 服务器的结果返回到原始请求方。That way, your logic app returns the results from your SAP server to the original requestor.

  1. 在逻辑应用设计器中的 SAP 操作下,选择“新建步骤”。 In the Logic App Designer, under the SAP action, select New step.

  2. 在搜索框中,输入“响应”作为筛选器。In the search box, enter "response" as your filter. 在“操作”列表中选择“响应”。 From the Actions list, select Response.

  3. 在“正文”框中单击,以显示动态内容列表。 Click inside the Body box so that the dynamic content list appears. 在该列表中的“将消息发送到 SAP”下面,选择“正文”字段。 From that list, under Send message to SAP, select the Body field.

    完成 SAP 操作

  4. 保存逻辑应用。Save your logic app.

测试逻辑应用Test your logic app

  1. 如果尚未启用逻辑应用,请在逻辑应用菜单中选择“概览”。 If your logic app isn't already enabled, on your logic app menu, select Overview. 在工具栏中选择“启用”。 On the toolbar, select Enable.

  2. 在设计器工具栏上选择“运行”。 On the designer toolbar, select Run. 此步骤会手动启动逻辑应用。This step manually starts your logic app.

  3. 通过将 HTTP POST 请求发送到 HTTP 请求触发器中的 URL 来触发逻辑应用。Trigger your logic app by sending an HTTP POST request to the URL in your HTTP Request trigger. 在请求中包括消息内容。Include your message content with your request. 若要发送请求,可以使用 Postman 等工具。To the send the request, you can use a tool such as Postman.

    在本文中,请求会发送 IDoc 文件,该文件必须采用 XML 格式,并且包含你所用 SAP 操作的命名空间,例如:For this article, the request sends an IDoc file, which must be in XML format and include the namespace for the SAP action you're using, for example:

    <?xml version="1.0" encoding="UTF-8" ?>
    <Send xmlns="http://Microsoft.LobServices.Sap/2007/03/Idoc/2/ORDERS05//720/Send">
       <idocData>
          <...>
       </idocData>
    </Send>
    
  4. 发送 HTTP 请求之后,等待逻辑应用返回响应。After you send your HTTP request, wait for the response from your logic app.

    Note

    如果未在请求超时限制所规定的时间内完成响应所需的所有步骤,逻辑应用可能会超时。Your logic app might time out if all the steps required for the response don't finish within the request timeout limit. 如果发生这种情况,请求可能会被阻止。If this condition happens, requests might get blocked. 为了诊断问题,请了解如何检查和监视逻辑应用To help you diagnose problems, learn how you can check and monitor your logic apps.

现已创建一个可与 SAP 服务器通信的逻辑应用。You've now created a logic app that can communicate with your SAP server. 为逻辑应用设置 SAP 连接后,可以探索其他可用的 SAP 操作,例如 BAPI 和 RFC。Now that you've set up an SAP connection for your logic app, you can explore other available SAP actions, such as BAPI and RFC.

从 SAP 接收消息Receive message from SAP

此示例使用当应用从 SAP 系统收到消息时触发的逻辑应用。This example uses a logic app that triggers when the app receives a message from an SAP system.

添加 SAP 触发器Add an SAP trigger

  1. 在 Azure 门户中创建一个空白的逻辑应用,以便打开逻辑应用设计器。In the Azure portal, create a blank logic app, which opens the Logic App Designer.

  2. 在搜索框中,输入“sap”作为筛选器。In the search box, enter "sap" as your filter. 在“触发器”列表中选择“从 SAP 收到消息时”。 From the Triggers list, select When a message is received from SAP.

    添加 SAP 触发器

    也可选择“企业”选项卡,然后选择触发器: Or, you can select the Enterprise tab, and then select the trigger:

    在“企业”选项卡中添加 SAP 触发器

  3. 如果连接已存在,请继续下一步,以便可以设置 SAP 操作。If your connection already exists, continue with the next step so you can set up your SAP action. 但是,如果系统提示输入连接详细信息,请提供该信息,以便立即创建到本地 SAP 服务器的连接。However, if you're prompted for connection details, provide the information so that you can create a connection to your on-premises SAP server now.

    1. 为连接提供一个名称。Provide a name for the connection.

    2. 在“数据网关”部分的“订阅”下,首先选择在 Azure 门户中为网关安装创建的网关资源的 Azure 订阅。 In the Data Gateway section, under Subscription, first select the Azure subscription for the gateway resource that you created in the Azure portal for your gateway installation.

    3. 在“连接网关”下,选择网关资源。 Under Connection Gateway, select your gateway resource.

    4. 继续提供有关连接的信息。Continue providing information about the connection. 对于“登录类型”属性,请根据该属性是设置为“应用程序服务器”还是“组”来执行相关步骤: For the Logon Type property, follow the step based on whether the property is set to Application Server or Group:

      • 对于“应用程序服务器”,必须指定以下属性(通常显示为可选): For Application Server, these properties, which usually appear optional, are required:

      创建 SAP 应用程序服务器连接

      • 对于“组”,必须指定以下属性(通常显示为可选): For Group, these properties, which usually appear optional, are required:

      创建 SAP 消息服务器连接

      默认会使用强类型化通过针对架构执行 XML 验证来检查无效值。By default, strong typing is used to check for invalid values by performing XML validation against the schema. 此行为可帮助提前检测问题。This behavior can help you detect issues earlier. “安全类型化”选项用于实现后向兼容,它只会检查字符串长度。 The Safe Typing option is available for backward compatibility and only checks the string length. 详细了解安全类型化选项Learn more about the Safe Typing option.

    5. 完成后,选择“创建” 。When you're finished, select Create.

      逻辑应用会设置并测试连接,确保连接正常工作。Logic Apps sets up and tests your connection to make sure that the connection works properly.

  4. 根据 SAP 系统配置提供所需的参数。Provide the required parameters based on your SAP system configuration.

    可以选择性地提供一个或多个 SAP 操作。You can optionally provide one or more SAP actions. 此操作列表指定触发器通过数据网关从 SAP 服务器接收的消息。This list of actions specifies the messages that the trigger receives from your SAP server through the data gateway. 空列表指定触发器接收所有消息。An empty list specifies that the trigger receives all messages. 如果列表中不包含多条消息,则触发器只会接收列表中指定的消息。If the list has more than one message, the trigger receives only the messages specified in the list. 网关会拒绝从 SAP 服务器发送的其他任何消息。Any other messages sent from your SAP server are rejected by the gateway.

    可以通过文件选取器选择 SAP 操作:You can select an SAP action from the file picker:

    选择 SAP 操作

    或者,可以手动指定操作:Or you can manually specify an action:

    手动输入 SAP 操作

    以下示例演示将触发器设置为接收多个消息时操作的显示方式。Here's an example that shows how the action appears when you set up the trigger to receive more than one message.

    触发器示例

    有关 SAP 操作的详细信息,请参阅 IDOC 操作的消息架构For more information about the SAP action, see Message schemas for IDOC operations

  5. 现在请保存逻辑应用,以便可以开始从 SAP 系统接收消息。Now save your logic app so you can start receiving messages from your SAP system. 在设计器工具栏上选择“保存”。 On the designer toolbar, select Save.

现在,逻辑应用已准备好从 SAP 系统接收消息。Your logic app is now ready to receive messages from your SAP system.

Note

SAP 触发器不是轮询触发器,而是基于 Webhook 的触发器。The SAP trigger isn't a polling trigger but is a webhook-based trigger instead. 仅当存在消息时,才会从网关调用触发器,因此无需轮询。The trigger is called from the gateway only when a message exists, so no polling is necessary.

测试逻辑应用Test your logic app

  1. 若要触发逻辑应用,请从 SAP 系统发送一条消息。To trigger your logic app, send a message from your SAP system.

  2. 在逻辑应用菜单中,选择“概述” 。On the logic app menu, select Overview. 查看逻辑应用的所有新运行的“运行历史记录”。 Review the Runs history for any new runs for your logic app.

  3. 打开最近的运行,触发器输出部分会显示从 SAP 系统发送的消息。Open the most recent run, which shows the message sent from your SAP system in the trigger outputs section.

从 SAP 接收 IDOC 数据包Receive IDOC packets from SAP

可以将 SAP 设置为以数据包的形式发送 IDOC,数据包是成批或成组的 IDOC。You can set up SAP to send IDOCs in packets, which are batches or groups of IDOCs. SAP 连接器和其他组件(具体说来是触发器)不需额外配置即可接收 IDOC 数据包。To receive IDOC packets, the SAP connector, and specifically the trigger, doesn't need extra configuration. 但是,若要在触发器接收 IDOC 数据包之后处理该数据包中的每个项,必须执行一些其他的步骤,将数据包拆分成单个 IDOC。However, to process each item in an IDOC packet after the trigger receives the packet, some additional steps are required to split the packet into individual IDOCs.

下面是一个示例,演示如何使用 xpath() 函数从数据包提取单个 IDOC:Here's an example that shows how to extract individual IDOCs from a packet by using the xpath() function:

  1. 在开始之前,需要一个带 SAP 触发器的逻辑应用。Before you start, you need a logic app with an SAP trigger. 如果还没有该逻辑应用,请按本主题中的上述步骤操作,设置一个带 SAP 触发器的逻辑应用If you don't already have this logic app, follow the previous steps in this topic to set up a logic app with an SAP trigger.

    例如:For example:

    SAP 触发器

  2. 从 XML IDOC 获取根命名空间,该 IDOC 是逻辑应用从 SAP 接收的。Get the root namespace from the XML IDOC that your logic app receives from SAP. 若要从 XML 文档提取该命名空间,请添加一个步骤,使用 xpath() 表达式创建本地字符串变量并存储该命名空间:To extract this namespace from the XML document, add a step that creates a local string variable and stores that namespace by using an xpath() expression:

    xpath(xml(triggerBody()?['Content']), 'namespace-uri(/*)')

    获取命名空间

  3. 若要提取单个 IDOC,请添加一个步骤,使用另一个 xpath() 表达式创建数组变量并存储 IDOC 集合:To extract an individual IDOC, add a step that creates an array variable and stores the IDOC collection by using another xpath() expression:

    xpath(xml(triggerBody()?['Content']), '/*[local-name()="Receive"]/*[local-name()="idocData"]')

    获取项的数组

    数组变量通过对集合进行枚举,使每个 IDOC 可供逻辑应用单独处理。The array variable makes each IDOC available for your logic app to process individually by enumerating over the collection. 在以下示例中,逻辑应用使用循环将每个 IDOC 传输给 SFTP 服务器:In this example, the logic app transfers each IDOC to an SFTP server by using a loop:

    发送 IDOC

    每个 IDOC 必须包含根命名空间,因此必须将文件内容与根命名空间一起包装在 <Receive></Receive 元素中,然后才能将 IDOC 发送到下游应用(在此示例中为 SFTP 服务器)。Each IDOC must include the root namespace, which is the reason why the file content is wrapped inside a <Receive></Receive element along with the root namespace before sending the IDOC to the downstream app, or SFTP server in this case.

Tip

可以将快速入门模板用于此模式,只需在创建新逻辑应用时在逻辑应用设计器中选择此模板即可。You can use the quickstart template for this pattern by selecting this template in the Logic App Designer when you create a new logic app.

选择批处理逻辑应用模板

为 SAP 中的项目生成架构Generate schemas for artifacts in SAP

本示例使用可通过 HTTP 请求触发的逻辑应用。This example uses a logic app that you can trigger with an HTTP request. SAP 操作将请求发送到 SAP 系统,以便为指定的中间文档 (IDoc) 和 BAPI 生成架构。The SAP action sends a request to an SAP system to generate the schemas for specified Intermediate Document (IDoc) and BAPI. 使用 Azure 资源管理器连接器将响应中返回的架构上传到集成帐户。Schemas that return in the response are uploaded to an Integration Account by using the Azure Resource Manager connector.

添加 HTTP 请求触发器Add an HTTP Request trigger

  1. 在 Azure 门户中创建一个空白的逻辑应用,以便打开逻辑应用设计器。In the Azure portal, create a blank logic app, which opens the Logic App Designer.

  2. 在搜索框中,输入“http 请求”作为筛选器。In the search box, enter "http request" as your filter. 从触发器列表中选择此触发器:请求 - 当收到 HTTP 请求时From the triggers list, select this trigger: Request - When a HTTP request is received

    添加 HTTP 请求触发器

  3. 现在请保存逻辑应用,以便为逻辑应用生成终结点 URL。Now save your logic app so you can generate an endpoint URL for your logic app. 在设计器工具栏上选择“保存”。 On the designer toolbar, select Save.

    终结点 URL 现在会显示在触发器中,例如:The endpoint URL now appears in your trigger, for example:

    生成终结点的 URL

添加 SAP 操作以生成架构Add an SAP action to generate schemas

  1. 在逻辑应用设计器中的触发器下,选择“新建步骤”。 In the Logic App Designer, under the trigger, select New step.

    向逻辑应用添加新步骤

  2. 在搜索框中,输入“sap”作为筛选器。In the search box, enter "sap" as your filter. 在“操作”列表中选择“生成架构”。 From the Actions list, select Generate schemas.

    选择 SAP 发送操作

    或者,也可以选择“企业”选项卡,然后选择 SAP 操作。 Or, you also can choose the Enterprise tab, and select the SAP action.

    在“企业”选项卡中选择 SAP 发送操作

  3. 如果连接已存在,请继续下一步,以便可以设置 SAP 操作。If your connection already exists, continue with the next step so you can set up your SAP action. 但是,如果系统提示输入连接详细信息,请提供该信息,以便立即创建到本地 SAP 服务器的连接。However, if you're prompted for connection details, provide the information so that you can create a connection to your on-premises SAP server now.

    1. 为连接提供一个名称。Provide a name for the connection.

    2. 在“数据网关”部分的“订阅”下,首先选择在 Azure 门户中为网关安装创建的网关资源的 Azure 订阅。 In the Data Gateway section, under Subscription, first select the Azure subscription for the gateway resource that you created in the Azure portal for your gateway installation.

    3. 在“连接网关”下,选择网关资源。 Under Connection Gateway, select your gateway resource.

    4. 继续提供有关连接的信息。Continue providing information about the connection. 对于“登录类型”属性,请根据该属性是设置为“应用程序服务器”还是“组”来执行相关步骤: For the Logon Type property, follow the step based on whether the property is set to Application Server or Group:

      • 对于“应用程序服务器”,必须指定以下属性(通常显示为可选): For Application Server, these properties, which usually appear optional, are required:

      创建 SAP 应用程序服务器连接

      • 对于“组”,必须指定以下属性(通常显示为可选): For Group, these properties, which usually appear optional, are required:

        创建 SAP 消息服务器连接

      默认会使用强类型化通过针对架构执行 XML 验证来检查无效值。By default, strong typing is used to check for invalid values by performing XML validation against the schema. 此行为可帮助提前检测问题。This behavior can help you detect issues earlier. “安全类型化”选项用于实现后向兼容,它只会检查字符串长度。 The Safe Typing option is available for backward compatibility and only checks the string length. 详细了解“安全类型化”选项Learn more about the Safe Typing option.

    5. 完成后,选择“创建” 。When you're finished, select Create.

      逻辑应用会设置并测试连接,确保连接正常工作。Logic Apps sets up and tests your connection to make sure that the connection works properly.

  4. 提供要为其生成架构的项目的路径。Provide the path to the artifact for which you want to generate the schema.

    可以通过文件选取器选择 SAP 操作:You can select the SAP action from the file picker:

    选择 SAP 操作

    或者,可以手动输入操作:Or, you can manually enter the action:

    手动输入 SAP 操作

    若要为多个项目生成架构,请提供每个项目的 SAP 操作详细信息,例如:To generate schemas for more than one artifact, provide the SAP action details for each artifact, for example:

    选择“添加新项”

    显示两个项

    有关 SAP 操作的详细信息,请参阅 IDOC 操作的消息架构For more information about the SAP Action, see Message schemas for IDOC operations.

  5. 保存逻辑应用。Save your logic app. 在设计器工具栏上选择“保存”。 On the designer toolbar, select Save.

测试逻辑应用Test your logic app

  1. 在设计器工具栏上,选择“运行”以触发逻辑应用的运行。 On the designer toolbar, select Run to trigger a run for your logic app.

  2. 打开该运行,并检查“生成架构”操作的输出。 Open the run, and check the outputs for the Generate schemas action.

    输出中会显示针对指定的消息列表生成的架构。The outputs show the generated schemas for the specified list of messages.

将架构上传到集成帐户Upload schemas to an integration account

(可选)可以下载生成的架构,或将其存储在 Blob、存储或集成帐户等存储库中。Optionally, you can download or store the generated schemas in repositories, such as a blob, storage, or integration account. 集成帐户为其他 XML 操作提供一流的体验。本示例演示如何使用 Azure 资源管理器连接器将架构上传到同一逻辑应用的集成帐户。Integration accounts provide a first-class experience with other XML actions, so this example shows how to upload schemas to an integration account for the same logic app by using the Azure Resource Manager connector.

  1. 在逻辑应用设计器中的触发器下,选择“新建步骤”。 In the Logic App Designer, under the trigger, select New step.

  2. 在搜索框中,输入“资源管理器”作为筛选器。In the search box, enter "Resource Manager" as your filter. 选择“创建或更新资源”。 Select Create or update a resource.

    选择 Azure 资源管理器操作

  3. 输入操作的详细信息,包括 Azure 订阅、Azure 资源组和集成帐户。Enter the details for the action, including your Azure subscription, Azure resource group, and integration account. 若要将 SAP 令牌添加到字段,请在这些字段对应的框中单击,然后从显示的动态内容列表中选择。To add SAP tokens to the fields, click inside the boxes for those fields, and select from the dynamic content list that appears.

    1. 打开“添加新参数”列表,然后选择“位置”和“属性”字段。 Open the Add new parameter list, and select the Location and Properties fields.

    2. 按此示例所示,提供这些新字段的详细信息。Provide details for these new fields as shown in this example.

      输入 Azure 资源管理器操作的详细信息

    SAP 的“生成架构”操作会生成集合形式的架构,因此,设计器会自动将一个 For each 循环添加到该操作。 The SAP Generate schemas action generates schemas as a collection, so the designer automatically adds a For each loop to the action. 以下示例演示此操作的显示方式:Here's an example that shows how this action appears:

    包含“for each”循环的 Azure 资源管理器操作

    Note

    架构使用 base64 编码格式。The schemas use base64-encoded format. 若要将架构上传到集成帐户,必须使用 base64ToString() 函数将其解码。To upload the schemas to an integration account, they must be decoded by using the base64ToString() function. 以下示例演示了 "properties" 元素的代码:Here's an example that shows the code for the "properties" element:

    "properties": {
       "Content": "@base64ToString(items('For_each')?['Content'])",
       "ContentType": "application/xml",
       "SchemaType": "Xml"
    }
    
  4. 保存逻辑应用。Save your logic app. 在设计器工具栏上选择“保存”。 On the designer toolbar, select Save.

测试逻辑应用Test your logic app

  1. 在设计器工具栏上,选择“运行”以手动触发逻辑应用。 On the designer toolbar, select Run to manually trigger your logic app.

  2. 成功运行后,转到集成帐户,并检查生成的架构是否存在。After a successful run, go to the integration account, and check that the generated schemas exist.

启用安全网络通信Enable Secure Network Communications

在开始之前,请确保符合先前列出的先决条件Before you start, make sure that you met the previously listed prerequisites:

  • 本地数据网关已安装在 SAP 系统所在的位于同一网络中的某台计算机上。The on-premises data gateway is installed on a machine that's in the same network as your SAP system.
  • 为实现 SSO,需以映射到 SAP 用户的用户身份运行网关。For SSO, the gateway is running as a user that's mapped to an SAP user.
  • 提供其他安全功能的 SNC 库已安装在数据网关所在的同一台计算机上。The SNC library that provides the additional security functions is installed on the same machine as the data gateway. 部分示例包括 sapseculib、Kerberos 和 NTLM。Some examples include sapseculib, Kerberos, and NTLM.

若要对传入和传出 SAP 系统的请求启用 SNC,请在 SAP 连接中选中“使用 SNC”复选框,并提供以下属性: To enable SNC for your requests to or from the SAP system, select the Use SNC check box in the SAP connection and provide these properties:

在连接中配置 SAP SNC

属性Property 说明Description
SNC 库路径SNC Library Path SNC 库的名称、相对于 NCo 安装位置的路径或绝对路径。The SNC library name or path relative to NCo installation location or absolute path. 例如 sapsnc.dll.\security\sapsnc.dllc:\security\sapsnc.dllExamples are sapsnc.dll or .\security\sapsnc.dll or c:\security\sapsnc.dll.
SNC SSOSNC SSO 通过 SNC 进行连接时,SNC 标识通常用于对调用方进行身份验证。When you connect through SNC, the SNC identity is typically used for authenticating the caller. 另一个选项是重写,以便可以使用用户和密码信息对调用方进行身份验证,但该行仍会加密。Another option is to override so that user and password information can be used for authenticating the caller, but the line is still encrypted.
我的 SNC 名称SNC My Name 在大多数情况下可以省略此属性。In most cases, this property can be omitted. 安装的 SNC 解决方案通常知道自己的 SNC 名称。The installed SNC solution usually knows its own SNC name. 只有对于支持“多个标识”的解决方案,才需要指定用于此特定目标或服务器的标识。Only for solutions that support multiple identities, you might need to specify the identity to be used for this particular destination or server.
SNC 合作伙伴名称SNC Partner Name 后端 SNC 的名称。The name for the back-end SNC.
SNC 保护质量SNC Quality of Protection 此特定目标或服务器的 SNC 通信使用的服务质量。The quality of service to be used for SNC communication of this particular destination or server. 默认值由后端系统定义。The default value is defined by the back-end system. 最大值由 SNC 使用的安全产品定义。The maximum value is defined by the security product used for SNC.

Note

不要在装有数据网关和 SNC 库的计算机上设置 SNC_LIB 和 SNC_LIB_64 环境变量。Don't set the environment variables SNC_LIB and SNC_LIB_64 on the machine where you have the data gateway and the SNC library. 如果已设置这些环境变量,它们会优先于通过连接器传递的 SNC 库值。If set, they take precedence over the SNC library value passed through the connector.

安全类型化Safe typing

创建 SAP 连接时,默认会使用强类型化通过针对架构执行 XML 验证来检查无效值。By default, when you create your SAP connection, strong typing is used to check for invalid values by performing XML validation against the schema. 此行为可帮助提前检测问题。This behavior can help you detect issues earlier. “安全类型化”选项用于实现后向兼容,它只会检查字符串长度。 The Safe Typing option is available for backward compatibility and only checks the string length. 如果选择“安全类型化”,则 SAP 中的 DATS 类型和 TIMS 类型将被视为字符串而不是其 XML 等效形式 xs:datexs:time,其中 xmlns:xs="http://www.w3.org/2001/XMLSchema"If you choose Safe Typing, the DATS type and TIMS type in SAP are treated as strings rather than as their XML equivalents, xs:date and xs:time, where xmlns:xs="http://www.w3.org/2001/XMLSchema". 安全类型化会影响所有架构生成操作、“被发送”有效负载和“被接收”响应的发送消息,以及触发器的行为。Safe typing affects the behavior for all schema generation, the send message for both the "been sent" payload and the "been received" response, and the trigger.

使用强类型化时(未启用安全类型化),架构会将 DATS 和 TIMS 类型映射到更简单的 XML 类型:When strong typing is used (Safe Typing isn't enabled), the schema maps the DATS and TIMS types to more straightforward XML types:

<xs:element minOccurs="0" maxOccurs="1" name="UPDDAT" nillable="true" type="xs:date"/>
<xs:element minOccurs="0" maxOccurs="1" name="UPDTIM" nillable="true" type="xs:time"/>

使用强类型化发送消息时,DATS 和 TIMS 响应符合匹配的 XML 类型格式:When you send messages using strong typing, the DATS and TIMS response complies to the matching XML type format:

<DATE>9999-12-31</DATE>
<TIME>23:59:59</TIME>

启用安全类型化时,架构会将 DATS 和 TIMS 类型映射到只施加长度限制的 XML 字符串字段,例如:When Safe Typing is enabled, the schema maps the DATS and TIMS types to XML string fields with length restrictions only, for example:

<xs:element minOccurs="0" maxOccurs="1" name="UPDDAT" nillable="true">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:maxLength value="8" />
    </xs:restriction>
  </xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="UPDTIM" nillable="true">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:maxLength value="6" />
    </xs:restriction>
  </xs:simpleType>
</xs:element>

在启用安全类型化的情况下发送消息时,DATS 和 TIMS 响应如以下示例所示:When messages are sent with Safe Typing enabled, the DATS and TIMS response looks like this example:

<DATE>99991231</DATE>
<TIME>235959</TIME>

高级方案Advanced scenarios

显式确认事务Confirm transaction explicitly

将事务从逻辑应用发送到 SAP 时,此交换以两步方式完成,详见 SAP 文档:Transactional RFC Server Programs(事务性 RFC 服务器程序)。When you send transactions to SAP from Logic Apps, this exchange happens in two steps as described in the SAP document, Transactional RFC Server Programs. 默认情况下,“发送到 SAP”操作 在单个调用中处理函数传输步骤和事务确认步骤。By default, the Send to SAP action handles both the steps for the function transfer and for the transaction confirmation in a single call. SAP 连接器提供将这两个步骤分离的选项。The SAP connector gives you the option to decouple these steps. 可以发送 IDOC,并且可以使用显式的“确认事务 ID”操作,而不自动对事务进行确认。 You can send an IDOC and rather than automatically confirm the transaction, you can use the explicit Confirm transaction ID action.

不想在 SAP 中复制事务时(例如,在由于网络问题之类的原因而导致故障的情况下),可以使用这个分离事务 ID 确认的功能。This capability to decouple the transaction ID confirmation is useful when you don't want to duplicate transactions in SAP, for example, in scenarios where failures might happen due to causes such as network issues. 采用单独确认事务 ID 的方式,事务只在 SAP 系统中完成一次。By confirming the transaction ID separately, the transaction is only completed one time in your SAP system.

下面以示例方式展示了此模式:Here is an example that shows this pattern:

  1. 创建空的逻辑应用并添加 HTTP 触发器。Create a blank logic app and add an HTTP trigger.

  2. 在 SAP 连接器中,添加“发送 IDOC”操作。 From the SAP connector, add the Send IDOC action. 提供发送到 SAP 系统的 IDOC 的详细信息。Provide the details for the IDOC that you send to your SAP system.

  3. 若要在单独的步骤中显式确认事务 ID,请在“确认 TID”字段中选择“否”。 To explicitly confirm the transaction ID in a separate step, in the Confirm TID field, select No. 对于可选的“事务 ID GUID”字段, 可以手动指定值,也可以让连接器自动生成该 GUID 并在“发送 IDOC”操作的响应中将其返回。For the optional Transaction ID GUID field, you can either manually specify the value or have the connector automatically generate and return this GUID in the response from the Send IDOC action.

    “发送 IDOC”操作的属性

  4. 若要显式确认事务 ID,请添加“确认事务 ID”操作。 To explicitly confirm the transaction ID, add the Confirm transaction ID action. 在“事务 ID”框中单击,以显示动态内容列表。 Click inside the Transaction ID box so that the dynamic content list appears. 在该列表中选择从“发送 IDOC”操作返回的“事务 ID”值。 From that list, select the Transaction ID value that's returned from the Send IDOC action.

    “确认事务 ID”操作

    此步骤完成以后,会在两端(SAP 连接器端和 SAP 系统端)将当前的事务标记为完成。After this step runs, the current transaction is marked complete at both ends, on the SAP connector side and on SAP system side.

已知问题和限制Known issues and limitations

下面是 SAP 连接器目前存在的已知问题和限制:Here are the currently known issues and limitations for the SAP connector:

  • SAP 触发器不支持数据网关群集。The SAP trigger doesn't support data gateway clusters. 在某些故障转移案例中,与 SAP 系统通信的数据网关节点可能不同于主动节点,从而导致意外的行为。In some failover cases, the data gateway node that communicates with the SAP system might differ from the active node, which results in unexpected behavior. 对于“发送”方案,支持使用数据网关群集。For send scenarios, data gateway clusters are supported.
  • SAP 连接器目前不支持 SAP 路由器字符串。The SAP connector currently doesn't support SAP router strings. 本地数据网关必须位于要连接的 SAP 系统所在的同一 LAN 中。The on-premises data gateway must exist on the same LAN as the SAP system you want to connect.

连接器参考Connector reference

有关触发器、操作和限制(请参阅连接器的 OpenAPI(以前称为 Swagger)说明)的技术详细信息,请查看连接器的参考页For technical details about triggers, actions, and limits, which are described by the connector's OpenAPI (formerly Swagger) description, review the connector's reference page.

后续步骤Next steps