#-Function Load-NCo---------------------------------------------------
#-
#- The loading of the NCo libraries is in dependence to the shell.
#- The 64-bit version loads the libraries from the path x64, and the
#- 32-bit version from the path x86.
#-
#---------------------------------------------------------------------
Function Load-NCo {
$CurrentDir = Get-Location
[System.IO.Directory]::SetCurrentDirectory($CurrentDir.Path)
$Size = [System.IntPtr]::Size
if ($Size -eq 4) {
$Path = $CurrentDir.Path + "\x86\"
}
elseif ($Size -eq 😎 {
$Path = $CurrentDir.Path + "\x64\"
}
$rc = [Reflection.Assembly]::LoadFile($Path + "sapnco.dll")
$rc = [Reflection.Assembly]::LoadFile($Path + "sapnco_utils.dll")
}
#-Function Get-Destination--------------------------------------------
Function Get-Destination {
#-Verbindungsparamter---------------------------------------------
$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")
$SecPasswd = Read-Host -Prompt "Passwort" -AsSecureString
$ptrPasswd = [Runtime.InteropServices.Marshal]::SecureStringToBStr($SecPasswd)
$Passwd = [Runtime.InteropServices.Marshal]::PtrToStringBStr($ptrPasswd)
$cfgParams.Add("PASSWD", $Passwd)
return [SAP.Middleware.Connector.RfcDestinationManager]::GetDestination($cfgParams)
}
#-Begin-----------------------------------------------------------------
#-Function Load-NCo---------------------------------------------------
Function Load-NCo {
$CurrentDir = Get-Location
[System.IO.Directory]::SetCurrentDirectory($CurrentDir.Path)
$Size = [System.IntPtr]::Size
if ($Size -eq 4) {
$Path = $CurrentDir.Path + "\x86\"
}
elseif ($Size -eq 😎 {
$Path = $CurrentDir.Path + "\x64\"
}
$rc = [Reflection.Assembly]::LoadFile($Path + "sapnco.dll")
$rc = [Reflection.Assembly]::LoadFile($Path + "sapnco_utils.dll")
}
#-Function Get-Destination--------------------------------------------
Function Get-Destination {
#-Connectionparamter----------------------------------------------
$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")
return [SAP.Middleware.Connector.RfcDestinationManager]::GetDestination($cfgParams)
}
#-Function Invoke-SAPFunctionModule-----------------------------------
Function Invoke-SAPFunctionModule {
$destination = Get-Destination
#-Metadata--------------------------------------------------------
[SAP.Middleware.Connector.IRfcFunction]$rfcFunction =
$destination.Repository.CreateFunction("STFC_CONNECTION")
#-Set importparameter---------------------------------------------
$rfcFunction.SetValue("REQUTEXT", "Hello World from PowerShell")
#-Call function module--------------------------------------------
$rfcFunction.Invoke($destination)
#-Show exportparameter--------------------------------------------
Write-Host $rfcFunction.GetValue("ECHOTEXT")
Write-Host $rfcFunction.GetValue("RESPTEXT")
}
#-Main----------------------------------------------------------------
Load-NCo
Invoke-SAPFunctionModule
#-End-------------------------------------------------------------------
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
3 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |