1

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")
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Paweł M.
  • 41
  • 6
  • Well... do you get an error? What is the actual problem you're having? – Nick.Mc Feb 07 '17 at 09:48
  • sory, first post :) corrected – Paweł M. Feb 07 '17 at 09:54
  • 1
    I've edited your question and written the full error message. Please add the rest if you can. It seems like one of your variables, maybe `$destination` has not been instantiated properly. Are there messages before this that have scrolled off? – Nick.Mc Feb 07 '17 at 10:08

0 Answers0