Connect Workday to your favorite reporting tools without moving data.
Learn More →Automate SAP Netweaver Gateway Integration Tasks from PowerShell
Are you looking for a quick and easy way to access SAP Netweaver Gateway data from PowerShell? We show how to use the Cmdlets for SAP Netweaver Gateway and the CData ADO.NET Provider for SAP Netweaver Gateway to connect to SAP Netweaver Gateway data and synchronize, automate, download, and more.
The CData Cmdlets for SAP Netweaver Gateway are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to SAP Netweaver Gateway.
Cmdlets or ADO.NET?
The cmdlets are not only a PowerShell interface to the SAP Netweaver Gateway API, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete SAP Netweaver Gateway data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for SAP Netweaver Gateway. To access SAP Netweaver Gateway data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for SAP Netweaver Gateway.
After obtaining the needed connection properties, accessing SAP Netweaver Gateway data in PowerShell consists of three basic steps.
SAP Gateway allows both basic and OAuth 2.0 authentication. You can use basic authentication to connect to your own account, or you can use OAuth to enable other users to retrieve data from your service with their accounts. In addition to authenticating, set the following connection properties to access SAP Gateway tables.
- Url: Set this to the URL of your environment, or to the full URL of the service. For example, the full URL might appear as: https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/. In this example, the environment URL would just be: https://sapes5.sapdevcenter.com.
- Namespace: Set the appropriate Service Namespace. In the example above, IWBEP is the namespace. It is optional if the full URL to the service is specified.
- Service: Set this to the service you want to retrieve data from. In the example above, the service is GWSAMPLE_BASIC. It is not required if the full URL is specified.
Authenticate via Basic Authentication
In basic authentication, you use your login credentials to connect. Set the following properties:
- User: This is the username you use to log in to SAP Gateway.
- Password: This is the password you use to log in to SAP Gateway.
Authenticate via OAuth Authentication
You can connect to SAP Gateway using the embedded OAuth connectivity (without setting any additional authentication connection properties). When you connect, the OAuth endpoint opens in your browser. Log in and grant permissions to complete the OAuth process. See the OAuth section in the online Help documentation for more information on other OAuth authentication flows.
PowerShell
-
Install the module:
Install-Module SAPGatewayCmdlets
-
Connect:
$sapgateway = Connect-SAPGateway -User "$User" -Password "$Password" -URL "$URL"
-
Search for and retrieve data:
$quantity = "15" $salesorderlineitems = Select-SAPGateway -Connection $sapgateway -Table "SalesOrderLineItems" -Where "Quantity = `'$Quantity`'" $salesorderlineitems
You can also use the Invoke-SAPGateway cmdlet to execute SQL commands:
$salesorderlineitems = Invoke-SAPGateway -Connection $sapgateway -Query 'SELECT * FROM SalesOrderLineItems WHERE Quantity = @Quantity' -Params @{'@Quantity'='15'}
ADO.NET
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for SAP Netweaver Gateway\lib\System.Data.CData.SAPGateway.dll")
-
Connect to SAP Netweaver Gateway:
$conn= New-Object System.Data.CData.SAPGateway.SAPGatewayConnection("User=user;Password=password;URL=https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/;InitiateOAuth=GETANDREFRESH") $conn.Open()
-
Instantiate the SAPGatewayDataAdapter, execute an SQL query, and output the results:
$sql="SELECT ProductID, Quantity from SalesOrderLineItems" $da= New-Object System.Data.CData.SAPGateway.SAPGatewayDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.productid $_.quantity }
Update SAP Netweaver Gateway Data
PowerShell
Update-SAPGateway -Connection $SAPGateway -Columns @('ProductID','Quantity') -Values @('MyProductID', 'MyQuantity') -Table SalesOrderLineItems -Id "MyId"
ADO.NET
$cmd = New-Object System.Data.CData.SAPGateway.SAPGatewayCommand("UPDATE SalesOrderLineItems SET Quantity='15' WHERE Id = @myId", $conn)
$cmd.Parameters.Add(new System.Data.CData.SAPGateway.SAPGatewayParameter("@myId","10456255-0015501366"))
$cmd.ExecuteNonQuery()
Insert SAP Netweaver Gateway Data
PowerShell
Add-SAPGateway -Connection $SAPGateway -Table SalesOrderLineItems -Columns @("ProductID", "Quantity") -Values @("MyProductID", "MyQuantity")
ADO.NET
$cmd = New-Object System.Data.CData.SAPGateway.SAPGatewayCommand("INSERT INTO SalesOrderLineItems (Quantity) VALUES (@myQuantity)", $conn)
$cmd.Parameters.Add(new System.Data.CData.SAPGateway.SAPGatewayParameter("@myQuantity","15"))
$cmd.ExecuteNonQuery()
Delete SAP Netweaver Gateway Data
PowerShell
Remove-SAPGateway -Connection $SAPGateway -Table "SalesOrderLineItems" -Id "MyId"
ADO.NET
$cmd = New-Object System.Data.CData.SAPGateway.SAPGatewayCommand("DELETE FROM SalesOrderLineItems WHERE Id=@myId", $conn)
$cmd.Parameters.Add(new System.Data.CData.SAPGateway.SAPGatewayParameter("@myId","001d000000YBRseAAH"))
$cmd.ExecuteNonQuery()
CodeProject