<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Calling an SAP web service from SQL server in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-an-sap-web-service-from-sql-server/m-p/12811236#M2025589</link>
    <description>&lt;P&gt;Hello!&lt;BR /&gt;How do I call an SAP web service from an SQL server? &lt;/P&gt;
  &lt;P&gt;I have tried a couple different ways in SQL to call the service, but either get NULL as a response, or an ‘Unsupported xstream found’ error.&lt;/P&gt;
  &lt;P&gt;Below is one of the procedures I tried calling the web service with: I’m just learning this aspect with SQL and web services so any help, or pointing in the right direction is very appreciated.&lt;/P&gt;
  &lt;P&gt; The @authHeader confuses me on passing the user:password. Any idea on the proper way to pass the user:password? &lt;/P&gt;
  &lt;P&gt;DECLARE @authHeader NVARCHAR(64);&lt;/P&gt;
  &lt;P&gt;DECLARE @contentType NVARCHAR(64);&lt;/P&gt;
  &lt;P&gt;DECLARE @postData NVARCHAR(2000);&lt;/P&gt;
  &lt;P&gt;DECLARE @responseText NVARCHAR(2000);&lt;/P&gt;
  &lt;P&gt;DECLARE @responseXML NVARCHAR(2000);&lt;/P&gt;
  &lt;P&gt;DECLARE @ret INT;&lt;/P&gt;
  &lt;P&gt;DECLARE @status NVARCHAR(32);&lt;/P&gt;
  &lt;P&gt;DECLARE @statusText NVARCHAR(32);&lt;/P&gt;
  &lt;P&gt;DECLARE @token INT;&lt;/P&gt;
  &lt;P&gt;DECLARE @url NVARCHAR(256);&lt;/P&gt;
  &lt;P&gt;--SET @authHeader = 'BASIC password???'; -- not sure if a key, or password goes here, if it is even needed&lt;/P&gt;
  &lt;P&gt;SET @contentType = 'application/x-www-form-urlencoded';&lt;/P&gt;
  &lt;P&gt;SET @postData = '&amp;lt;soapenv:Body&amp;gt;&lt;/P&gt;
  &lt;P&gt; &amp;lt;urn:ZppShopflrGetPlannedOrders&amp;gt;&lt;/P&gt;
  &lt;P&gt; &amp;lt;AlternativeBom&amp;gt;99&amp;lt;/AlternativeBom&amp;gt;&lt;/P&gt;
  &lt;P&gt; &amp;lt;BomCategory&amp;gt;Z&amp;lt;/BomCategory&amp;gt;&lt;/P&gt;
  &lt;P&gt; &amp;lt;Language&amp;gt;E&amp;lt;/Language&amp;gt;&lt;/P&gt;
  &lt;P&gt; &amp;lt;PartNumber&amp;gt;S999999999&amp;lt;/PartNumber&amp;gt;&lt;/P&gt;
  &lt;P&gt; &amp;lt;Plant&amp;gt;9999&amp;lt;/Plant&amp;gt;&lt;/P&gt;
  &lt;P&gt; &amp;lt;/urn:ZppShopflrGetPlannedOrders&amp;gt;&lt;/P&gt;
  &lt;P&gt; &amp;lt;/soapenv:Body&amp;gt;'&lt;/P&gt;
  &lt;P&gt;SET @url = 'http://frsl09v005.dp.net:8020/sap/bc/srt/rfc/sap/zpp_ws_get_planned_orders_df/100/get_planned_orders/get_planned_orders'&lt;/P&gt;
  &lt;P&gt;-- Open the connection.&lt;/P&gt;
  &lt;P&gt;EXEC @ret = sp_OACreate 'MSXML2.ServerXMLHTTP', @token OUT;&lt;/P&gt;
  &lt;P&gt;IF @ret &amp;lt;&amp;gt; 0 RAISERROR('Unable to open HTTP connection.', 10, 1);&lt;/P&gt;
  &lt;P&gt;-- Send the request.&lt;/P&gt;
  &lt;P&gt;EXEC @ret = sp_OAMethod @token, 'open', NULL, 'POST', @url, 'false';&lt;/P&gt;
  &lt;P&gt;--EXEC @ret = sp_OAMethod @token, 'setRequestHeader', NULL, 'Authentication', @authHeader;&lt;/P&gt;
  &lt;P&gt;EXEC @ret = sp_OAMethod @token, 'setRequestHeader', NULL, 'Content-type', @contentType;&lt;/P&gt;
  &lt;P&gt;EXEC @ret = sp_OAMethod @token, 'send', NULL, @postData;&lt;/P&gt;
  &lt;P&gt;-- Handle the response.&lt;/P&gt;
  &lt;P&gt;EXEC @ret = sp_OAGetProperty @token, 'status', @status OUT;&lt;/P&gt;
  &lt;P&gt;EXEC @ret = sp_OAGetProperty @token, 'statusText', @statusText OUT;&lt;/P&gt;
  &lt;P&gt;EXEC @ret = sp_OAGetProperty @token, 'responseText', @responseText OUT;&lt;/P&gt;
  &lt;P&gt;-- Show the response.&lt;/P&gt;
  &lt;P&gt;PRINT 'Status: ' + @status + ' (' + @statusText + ')';&lt;/P&gt;
  &lt;P&gt;PRINT 'Response text: ' + @responseText;&lt;/P&gt;
  &lt;P&gt;-- Close the connection.&lt;/P&gt;
  &lt;P&gt;EXEC @ret = sp_OADestroy @token;&lt;/P&gt;
  &lt;P&gt;IF @ret &amp;lt;&amp;gt; 0 RAISERROR('Unable to close HTTP connection.', 10, 1);&lt;/P&gt;
  &lt;P&gt;Error Returned;&lt;/P&gt;
  &lt;P&gt;Status: 500 (Internal Server Error)&lt;/P&gt;</description>
    <pubDate>Wed, 16 Aug 2023 15:32:24 GMT</pubDate>
    <dc:creator>murtuzakhanbsa</dc:creator>
    <dc:date>2023-08-16T15:32:24Z</dc:date>
    <item>
      <title>Calling an SAP web service from SQL server</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-an-sap-web-service-from-sql-server/m-p/12811236#M2025589</link>
      <description>&lt;P&gt;Hello!&lt;BR /&gt;How do I call an SAP web service from an SQL server? &lt;/P&gt;
  &lt;P&gt;I have tried a couple different ways in SQL to call the service, but either get NULL as a response, or an ‘Unsupported xstream found’ error.&lt;/P&gt;
  &lt;P&gt;Below is one of the procedures I tried calling the web service with: I’m just learning this aspect with SQL and web services so any help, or pointing in the right direction is very appreciated.&lt;/P&gt;
  &lt;P&gt; The @authHeader confuses me on passing the user:password. Any idea on the proper way to pass the user:password? &lt;/P&gt;
  &lt;P&gt;DECLARE @authHeader NVARCHAR(64);&lt;/P&gt;
  &lt;P&gt;DECLARE @contentType NVARCHAR(64);&lt;/P&gt;
  &lt;P&gt;DECLARE @postData NVARCHAR(2000);&lt;/P&gt;
  &lt;P&gt;DECLARE @responseText NVARCHAR(2000);&lt;/P&gt;
  &lt;P&gt;DECLARE @responseXML NVARCHAR(2000);&lt;/P&gt;
  &lt;P&gt;DECLARE @ret INT;&lt;/P&gt;
  &lt;P&gt;DECLARE @status NVARCHAR(32);&lt;/P&gt;
  &lt;P&gt;DECLARE @statusText NVARCHAR(32);&lt;/P&gt;
  &lt;P&gt;DECLARE @token INT;&lt;/P&gt;
  &lt;P&gt;DECLARE @url NVARCHAR(256);&lt;/P&gt;
  &lt;P&gt;--SET @authHeader = 'BASIC password???'; -- not sure if a key, or password goes here, if it is even needed&lt;/P&gt;
  &lt;P&gt;SET @contentType = 'application/x-www-form-urlencoded';&lt;/P&gt;
  &lt;P&gt;SET @postData = '&amp;lt;soapenv:Body&amp;gt;&lt;/P&gt;
  &lt;P&gt; &amp;lt;urn:ZppShopflrGetPlannedOrders&amp;gt;&lt;/P&gt;
  &lt;P&gt; &amp;lt;AlternativeBom&amp;gt;99&amp;lt;/AlternativeBom&amp;gt;&lt;/P&gt;
  &lt;P&gt; &amp;lt;BomCategory&amp;gt;Z&amp;lt;/BomCategory&amp;gt;&lt;/P&gt;
  &lt;P&gt; &amp;lt;Language&amp;gt;E&amp;lt;/Language&amp;gt;&lt;/P&gt;
  &lt;P&gt; &amp;lt;PartNumber&amp;gt;S999999999&amp;lt;/PartNumber&amp;gt;&lt;/P&gt;
  &lt;P&gt; &amp;lt;Plant&amp;gt;9999&amp;lt;/Plant&amp;gt;&lt;/P&gt;
  &lt;P&gt; &amp;lt;/urn:ZppShopflrGetPlannedOrders&amp;gt;&lt;/P&gt;
  &lt;P&gt; &amp;lt;/soapenv:Body&amp;gt;'&lt;/P&gt;
  &lt;P&gt;SET @url = 'http://frsl09v005.dp.net:8020/sap/bc/srt/rfc/sap/zpp_ws_get_planned_orders_df/100/get_planned_orders/get_planned_orders'&lt;/P&gt;
  &lt;P&gt;-- Open the connection.&lt;/P&gt;
  &lt;P&gt;EXEC @ret = sp_OACreate 'MSXML2.ServerXMLHTTP', @token OUT;&lt;/P&gt;
  &lt;P&gt;IF @ret &amp;lt;&amp;gt; 0 RAISERROR('Unable to open HTTP connection.', 10, 1);&lt;/P&gt;
  &lt;P&gt;-- Send the request.&lt;/P&gt;
  &lt;P&gt;EXEC @ret = sp_OAMethod @token, 'open', NULL, 'POST', @url, 'false';&lt;/P&gt;
  &lt;P&gt;--EXEC @ret = sp_OAMethod @token, 'setRequestHeader', NULL, 'Authentication', @authHeader;&lt;/P&gt;
  &lt;P&gt;EXEC @ret = sp_OAMethod @token, 'setRequestHeader', NULL, 'Content-type', @contentType;&lt;/P&gt;
  &lt;P&gt;EXEC @ret = sp_OAMethod @token, 'send', NULL, @postData;&lt;/P&gt;
  &lt;P&gt;-- Handle the response.&lt;/P&gt;
  &lt;P&gt;EXEC @ret = sp_OAGetProperty @token, 'status', @status OUT;&lt;/P&gt;
  &lt;P&gt;EXEC @ret = sp_OAGetProperty @token, 'statusText', @statusText OUT;&lt;/P&gt;
  &lt;P&gt;EXEC @ret = sp_OAGetProperty @token, 'responseText', @responseText OUT;&lt;/P&gt;
  &lt;P&gt;-- Show the response.&lt;/P&gt;
  &lt;P&gt;PRINT 'Status: ' + @status + ' (' + @statusText + ')';&lt;/P&gt;
  &lt;P&gt;PRINT 'Response text: ' + @responseText;&lt;/P&gt;
  &lt;P&gt;-- Close the connection.&lt;/P&gt;
  &lt;P&gt;EXEC @ret = sp_OADestroy @token;&lt;/P&gt;
  &lt;P&gt;IF @ret &amp;lt;&amp;gt; 0 RAISERROR('Unable to close HTTP connection.', 10, 1);&lt;/P&gt;
  &lt;P&gt;Error Returned;&lt;/P&gt;
  &lt;P&gt;Status: 500 (Internal Server Error)&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2023 15:32:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/calling-an-sap-web-service-from-sql-server/m-p/12811236#M2025589</guid>
      <dc:creator>murtuzakhanbsa</dc:creator>
      <dc:date>2023-08-16T15:32:24Z</dc:date>
    </item>
  </channel>
</rss>

