2021 Apr 08 11:53 AM
I´ve been tasked to implement a powershell script incorporating SAP .Net Connector, that execute a function, that loads a link and open it into a text file. The client examples I found in the documentation seemed simple enough, to translate those into powershell notation. When I execute my script, I receive following error:
“AusnahmebeimAufrufen von "Invoke" mit 1 Argument(en): "Callbacks from ABAP are not supported"
In C:\Users\sapuser\Desktop\script.ps1:49 Zeichen:10
+ $myFun.Invoke($destination)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo :NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId :RfcAbapRuntimeException
”
The code is simple, and basic to the code in the documentations, and works except of the invoke call:
#load .net sap connector
FunctionLoad-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")
}
FunctionGet-Destination2 {
#Connection paramenters
$cfgParams=New-ObjectSAP.Middleware.Connector.RfcConfigParameters
$cfgParams.Add("NAME","SAPconnect")
$cfgParams.Add("ASHOST","111.111.11.111")
$cfgParams.Add("SYSNR","11")
$cfgParams.Add("CLIENT","111")
$cfgParams.Add("USER","test")
$cfgParams.Add("SYSID ","test3")
$cfgParams.Add("LANG","DE")
$cfgParams.Add("PASSWD","test")
$destination=[SAP.Middleware.Connector.RfcDestinationManager]::GetDestination($cfgParams)
$rfcRepository=[SAP.Middleware.Connector.RfcDestination]
$rfcRepository=$destination.Repository
$myFun=[SAP.Middleware.Connector.IRfcFunction]
#rfc function module load
$myFun=$rfcRepository.CreateFunction("Z_GET_ARCHIVE_FILE_URL")
#write-host $myFun
#fill import parameters
$myFun.setValue("SAP_OBJECT","test1")
$myFun.setValue("OBJECT_ID","1234")
$myFun.setValue("ARCHIV_TAB","TEST01")
$myFun.setValue("ARCHIV_ID","T5")
$myFun.setValue("AR_OBJECT","TEST555")
$myFun.Invoke($destination) # Error
#write-host $myFun
#gettable "Data" from the function module
$table=$myFun.GetTable("T_URLS")
#write-host "tg" $table.Columns.count
}
Load-NCo
Get-Destination2
I´ve never worked with SAP, Powershell or SAP Connector before, and I really don´t know how to correct this. I know that NCo 3.0 don’t support the feature of a callback method (written here: "Callback not supported" error when invoking a function from C# .Net | SAP Community)
Is there another way to execute a callback like I want it? Any suggestions or code examples would be greatly appreciated.
2021 Apr 12 6:28 AM
Hi,
I'm leaving this solution for everybody who might have the same issue. I am the ABAP developer in the same company who created the function module Z_GET_ARCHIVE_FILE_URL and Tobias contacted me after receiving Sandra's answer. We were able to solve the issue in a very smooth way, without changing the function module.
SAP provides a User Parameter called "LCA" which can be used to prevent this error in this specific case. The solution for us was adding "LCA" to the RFC-User, using the RFC-Program-Name as its value for our information, but technically you can set any value for this usecase. The code will no longer do a callback in this case, once "LCA" is defined with any value.
To give some deeper input: Z_GET_ARCHIVE_FILE_URL is intended to return the Archive Link HTTPS URL(s) for specific documents linked to a Purchase Order. Therefore "SCMS_AO_URL_READ" gets called within the function module. After some debugging we were able to figure out that this function module caused the error. SAP also created a dump in ST22, but the information stated there was incomplete, since it only detected the header line of Z_GET_ARCHIVE_FILE_URL to be the code line causing the error. After multiple debugging and tracing steps we could find the real code that caused the issue.
Navigating a little bit back, while trying to prevent calling this line, I noticed within SCMS_LOCATION_GET at line 29 SAP is reading the parameter "LCA" and if it returns sy-subrc = 0 it leaves the function module SCMS_LOCATION_GET with EXIT, resulting in not calling the callback line at all. Apparently, this callback is not required in order to get the correct Archive-Link URLs. I could confirm this, since it is not getting called either, when you call the code from Front-end using SAPGUI.
Once LCA was added to the RFC-User-Parameters with any value (we picked the RFC-Program-Name), the error did no longer appear and SCMS_AO_URL_READ was able to return the correct Archive-Link URLs to Z_GET_ARCHIVE_FILE_URL which were correctly returned to the SAP .Net Connector called from PowerShell. "$table" from above's code then contained the URLs and Tobias was able to continue his work.
Regards.
2021 Apr 08 12:50 PM
If Z_GET_ARCHIVE_FILE_URL doesn't do a callback, your call would succeed... Change Z_GET_ARCHIVE_FILE_URL so that it doesn't do a callback.
2021 Apr 12 6:28 AM
sandra.rossi Thank you for pointing this out to Tobias. I am the ABAP developer in the same company who created the function module Z_GET_ARCHIVE_FILE_URL and Tobias contacted me after receiving your answer. We were able to solve the issue in a very smooth way, without changing the function module. I will post the solution as an answer to this topic below.
2021 Apr 12 6:28 AM
Hi,
I'm leaving this solution for everybody who might have the same issue. I am the ABAP developer in the same company who created the function module Z_GET_ARCHIVE_FILE_URL and Tobias contacted me after receiving Sandra's answer. We were able to solve the issue in a very smooth way, without changing the function module.
SAP provides a User Parameter called "LCA" which can be used to prevent this error in this specific case. The solution for us was adding "LCA" to the RFC-User, using the RFC-Program-Name as its value for our information, but technically you can set any value for this usecase. The code will no longer do a callback in this case, once "LCA" is defined with any value.
To give some deeper input: Z_GET_ARCHIVE_FILE_URL is intended to return the Archive Link HTTPS URL(s) for specific documents linked to a Purchase Order. Therefore "SCMS_AO_URL_READ" gets called within the function module. After some debugging we were able to figure out that this function module caused the error. SAP also created a dump in ST22, but the information stated there was incomplete, since it only detected the header line of Z_GET_ARCHIVE_FILE_URL to be the code line causing the error. After multiple debugging and tracing steps we could find the real code that caused the issue.
Navigating a little bit back, while trying to prevent calling this line, I noticed within SCMS_LOCATION_GET at line 29 SAP is reading the parameter "LCA" and if it returns sy-subrc = 0 it leaves the function module SCMS_LOCATION_GET with EXIT, resulting in not calling the callback line at all. Apparently, this callback is not required in order to get the correct Archive-Link URLs. I could confirm this, since it is not getting called either, when you call the code from Front-end using SAPGUI.
Once LCA was added to the RFC-User-Parameters with any value (we picked the RFC-Program-Name), the error did no longer appear and SCMS_AO_URL_READ was able to return the correct Archive-Link URLs to Z_GET_ARCHIVE_FILE_URL which were correctly returned to the SAP .Net Connector called from PowerShell. "$table" from above's code then contained the URLs and Tobias was able to continue his work.
Regards.
2021 Oct 04 12:48 PM
2021 Oct 04 1:03 PM