Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
stefan_schnell
Active Contributor
PowerShell is in standard available on any Windows 7 and higher and it bases on dotNET. You can find a lot of information here. PowerShell offers a good integrated scripting environment (ISE), so it is very easy to code and test scripts.

SAP offers with the dotNET Connector (NCo) an easy way to use the SAP backend in this environment. You can find NCo here. The NCo is primarly used with C# language and you can find a lot of examples.

I combine the possibilities of PowerShell and NCo, to show how easy and fast you can create a communication between your presentation server and the application server. The first example shows only the version number of the NCo:
#-Begin-----------------------------------------------------------------

#-Function Get-NCoVersion---------------------------------------------
Function Get-NCoVersion {

#-Loads NCo libraries---------------------------------------------
$rc = [Reflection.Assembly]::LoadFile("C:\NCo\sapnco.dll")
$rc = [Reflection.Assembly]::LoadFile("C:\NCo\sapnco_utils.dll")

#-Gets the version of NCo-----------------------------------------
$Version =
[SAP.Middleware.Connector.SAPConnectorInfo]::get_Version()
$PatchLevel =
[SAP.Middleware.Connector.SAPConnectorInfo]::get_KernelPatchLevel()
$SAPRelease =
[SAP.Middleware.Connector.SAPConnectorInfo]::get_SAPRelease()

#-Shows the result------------------------------------------------
Write-Host "`r`nNCo verion:" $Version
Write-Host "Patch Level:" $PatchLevel
Write-Host "SAP Release:" $SAPRelease

}

#-Main----------------------------------------------------------------
Get-NCoVersion

#-End-------------------------------------------------------------------

 



The second example shows how to call a function module, with import and export parameters:
#-Begin-----------------------------------------------------------------

#-Function Invoke-SAPFunctionModule-----------------------------------
Function Invoke-SAPFunctionModule {

#-Loads NCo libraries---------------------------------------------
$rc = [Reflection.Assembly]::LoadFile("C:\NCo\sapnco.dll")
$rc = [Reflection.Assembly]::LoadFile("C:\NCo\sapnco_utils.dll")

#-Sets connection parameters--------------------------------------
$cfgParams = New-Object SAP.Middleware.Connector.RfcConfigParameters
$cfgParams.Add("NAME", "TEST")
$cfgParams.Add("ASHOST", "ABAP")
$cfgParams.Add("SYSNR", "00")
$cfgParams.Add("CLIENT", "001")
$cfgParams.Add("USER", "BCUSER")
$cfgParams.Add("PASSWD", "minisap")

#-Destination-----------------------------------------------------
$destination =
[SAP.Middleware.Connector.RfcDestinationManager]::GetDestination($cfgParams)

#-Metadata--------------------------------------------------------
[SAP.Middleware.Connector.IRfcFunction]$rfcFunction =
$destination.Repository.CreateFunction("STFC_CONNECTION")

#-Sets import parameter-------------------------------------------
$rfcFunction.SetValue("REQUTEXT", "Hello World from PowerShell")

#-Calls function module-------------------------------------------
$rfcFunction.Invoke($destination)

#-Shows export parameters-----------------------------------------
Write-Host $rfcFunction.GetValue("ECHOTEXT")
Write-Host $rfcFunction.GetValue("RESPTEXT")

}

#-Main----------------------------------------------------------------
Invoke-SAPFunctionModule

#-End-------------------------------------------------------------------

 



The PowerShell ISE offers a lot of additional things, e.g. like code completion.



With PowerShell and NCo you can easily create client functions. All you have to do is to copy the necessary NCo libraries on your presentation server. PowerShell is on Windows available and so you can start up quickly.