I´m writing a Powerhsell script that opens a order bill. First of all I set the connection - this works, because I tested it with the SAP GUI. I have the same script written in VBS, and I want to translate it. I get this error:
Ausnahme beim Aufrufen von "Invoke" mit 1 Argument(en): "TABLE_NOT_AVAILABLE"
In C:\Users\x\Desktop\script.ps1:70 Zeichen:9
+ $rfcFunction.Invoke($destination)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : RfcAbapException
But i know it has to be this directory. what is wrong with my script until that point.
My script in Powershell until yet:
#load .net sap connector
Function Load-NCo {
$CurrentDir = Get-Location
[System.IO.Directory]::SetCurrentDirectory($CurrentDir.Path)
$rc = [Reflection.Assembly]::LoadFile("C:\Program Files\SAP\SAP_DotNetConnector3_Net40_x64\" + "sapnco.dll")
$rc = [Reflection.Assembly]::LoadFile("C:\Program Files\SAP\SAP_DotNetConnector3_Net40_x64\" + "sapnco_utils.dll")
}
Function Get-Destination2 ([String]$TableName) {
#-Verbindungsparamter---------------------------------------------
$cfgParams = New-Object SAP.Middleware.Connector.RfcConfigParameters
$cfgParams.Add("NAME", "SAPconnect")
$cfgParams.Add("ASHOST", "xxx.xxx.xxx.xxx")
$cfgParams.Add("SYSNR", "xx")
$cfgParams.Add("CLIENT", "xxx")
$cfgParams.Add("USER", "testuser")
$cfgParams.Add("SYSID ","Txx")
$cfgParams.Add("LANG","DE")
$cfgParams.Add("PASSWD", "TestX")
$destination = [SAP.Middleware.Connector.RfcDestinationManager]::GetDestination($cfgParams)
#-Metadata--------------------------------------------------------
$rfcFunction = `
$destination.Repository.CreateFunction("RFC_READ_TABLE")
#-Call function module--------------------------------------------
$rfcFunction.SetValue("query_table", $TableName)
$rfcFunction.SetValue("DELIMITER", ";")
$rfcFunction.Invoke($destination)
Write-Host [SAP.Middleware.Connector.RfcDestinationManager]::GetDestination($cfgParams)
}
Load-NCo
Get-Destination2("Z_GET_ARCHIVE_FILE_URL")
According to this Guide to Using RFC_READ_TABLE to Query SAP Tables. This error is due to an incorrect table name being passed here:
For troubleshooting, try writing
$rfcFunctionand$destinationto the console: