Paweł M.
Paweł M.

Reputation: 51

How to get number of rows in SAP table by powershell using RFC?

I'm trying to reach number of rows in SAP table MARA using Powershell. I call EM_GET_NUMBER_OF_ENTRIES function. I don't know powershell well and have problem with correctly pass TABNAME value. I think the line $rfctableOut.SetValue("TABNAME","MARA") is incorrect.

Here's my script:

Function Invoke-SAPFunctionModule {
#-Loads NCo libraries-------------------------------------------------
$rc = [Reflection.Assembly]::LoadFile("C:\SAP\64\sapnco.dll")
$rc = [Reflection.Assembly]::LoadFile("C:\SAP\64\sapnco_utils.dll")

#-Sets connection parameters------------------------------------------
$cfgParams = New-Object SAP.Middleware.Connector.RfcConfigParameters

$cfgParams.Add("ASHOST", "SOME IP")
$cfgParams.Add("SYSNR", "20")
$cfgParams.Add("NAME", "SOME SYSTEM")
$cfgParams.Add("USER", "SOME USER")
$cfgParams.Add("PASSWD", "SOME PASS@")
$cfgParams.Add("CLIENT", "400")
$cfgParams.Add("LANG", "PL")
$cfgParams.Add("POOL_SIZE", "5") 


$destination =          [SAP.Middleware.Connector.RfcDestinationManager]::GetDestination($cfgParams)
[SAP.Middleware.Connector.IRfcFunction]$rfcFunction =   $destination.Repository.CreateFunction("EM_GET_NUMBER_OF_ENTRIES")

[SAP.Middleware.Connector.IRfcStructure] $rfctableOut = $rfcFunction.GetTable("IT_TABLES")
$rfctableOut.SetValue("TABNAME","MARA")
Write-Host $rfcFunction.GetValue("TABROWS")

}

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

And I have an error:

You cannot call a method on a null-valued expression

enter image description here

Line 24 is :

[SAP.Middleware.Connector.IRfcFunction]$rfcFunction =    
$destination.Repository.CreateFunction("EM_GET_NUMBER_OF_ENTRIES")

Upvotes: 1

Views: 1408

Answers (0)

Related Questions