![]() |
VOOZH | about |
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.
The Cmdlets are not only a PowerShell interface to SAP Netweaver Gateway, 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.
Once you have acquired the necessary connection properties, accessing SAP Netweaver Gateway data in PowerShell can be enabled in three 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.
In basic authentication, you use your login credentials to connect. Set the following properties:
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.
Install the module:
Install-Module SAPGatewayCmdlets
Connect:
$sapgateway = Connect-SAPGateway -User "$User" -Password "$Password" -URL "$URL" -InitiateOAuth "$InitiateOAuth"
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'}
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-SAPGateway -Connection $SAPGateway -Columns @('ProductID','Quantity') -Values @('MyProductID', 'MyQuantity') -Table SalesOrderLineItems -Id "MyId"
$cmd = New-Object System.Data.CData.SAPGateway.SAPGatewayCommand("UPDATE SalesOrderLineItems SET Quantity='15' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SAPGateway.SAPGatewayParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-SAPGateway -Connection $SAPGateway -Table SalesOrderLineItems -Columns @("ProductID", "Quantity") -Values @("MyProductID", "MyQuantity")
$cmd = New-Object System.Data.CData.SAPGateway.SAPGatewayCommand("INSERT INTO SalesOrderLineItems (Quantity) VALUES (@myQuantity)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SAPGateway.SAPGatewayParameter("@myQuantity","15")))
$cmd.ExecuteNonQuery()
Remove-SAPGateway -Connection $SAPGateway -Table "SalesOrderLineItems" -Id "MyId"
$cmd = New-Object System.Data.CData.SAPGateway.SAPGatewayCommand("DELETE FROM SalesOrderLineItems WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SAPGateway.SAPGatewayParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the SAP Netweaver Gateway Data Provider to get started:
Download NowLearn more:
👁 SAP Netweaver Gateway IconRapidly create and deploy powerful .NET applications that integrate with SAP Netweaver Gateway.