SAP / PyRFC

Asynchronous, non-blocking SAP NW RFC SDK bindings for Python
http://sap.github.io/PyRFC
Apache License 2.0
500 stars 132 forks source link

pyrfc._exception.ExternalRuntimeError: 13 (rc=13): key=RFC_INVALID_HANDLE, caused due to a table parameter without column filed? #341

Closed ZhipingWen closed 8 months ago

ZhipingWen commented 10 months ago

Describe the bug A clear and concise description of what the bug is. Once call SAP BAPI "SO_DOCUMENT_REPOSITORY_MANAGER", response with ExternalRuntimeError: 13 (rc=13): key=RFC_INVALID_HANDLE

To Reproduce Describe the steps to reproduce the behavior, including test script.

Screenshots If applicable, add screenshots to help explain your problem. 1) Code:

    with pyrfc.Connection(**conn_params) as conn:
        result = conn.call('SO_DOCUMENT_REPOSITORY_MANAGER',
                           METHOD = 'IMPORTFROMPC',
                           FILES = [dict("C:\\Users\\pk3100\\Downloads\\logo.gif")],
                           DOCUMENT = DS_Document,
                           HEADER_DATA = HEADER_DATA,
                           # FOLMEM_DATA = FOLMEM_DATA,
                           # RECEIVE_DATA = RECEIVE_DATA
                           )

2) Issue:

 result = conn.call('SO_DOCUMENT_REPOSITORY_MANAGER',
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "src\\pyrfc\\_cyrfc.pyx", line 933, in pyrfc._cyrfc.Connection.call
  File "src\\pyrfc\\_cyrfc.pyx", line 2471, in pyrfc._cyrfc.functionContainerSet
  File "src\\pyrfc\\_cyrfc.pyx", line 2525, in pyrfc._cyrfc.fillVariable
  File "src\\pyrfc\\_cyrfc.pyx", line 2492, in pyrfc._cyrfc.fillTable
pyrfc._exception.ExternalRuntimeError: 13 (rc=13): key=RFC_INVALID_HANDLE, message=An invalid handle 'RFC_TABLE_HANDLE' was passed to the API call [MSG: class=, type=, number=, v1-4:=;;;]

Environment

Additional context Add any other context about the problem here. For this BAPI "SO_DOCUMENT_REPOSITORY_MANAGER", there is a table parameter named FILES which has no any column name. I guess this issue is related to this parameter. In general, I transferred this parameter like [dict(filename with path)] with different ways, but always got same issue.

bsrdjan commented 10 months ago

Hello @ZhipingWen,

the RFC_INVALID_HANDLE should not happen in this case and I will investigate it. Are you sure the example code is copied correctly because the function dict("C:\Users\pk3100\Downloads\logo.gif") fails in my Python 3 interpreter:

dict("C:\Users\pk3100\Downloads\logo.gif")
  Cell In[12], line 1
    dict("C:\Users\pk3100\Downloads\logo.gif")
                                             ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

dict requires minimum minimum two parameters, as per documentation, but FILES are anyway not dictionary parameter. When no columns, the table is passed as array and you can try this instead. Note the escaped backslash character:

FILES = ["C:\\Users\\pk3100\\Downloads\\logo.gif"]
ZhipingWen commented 10 months ago

Hi bsrdjan, Many thanks for your support!

Yes, you are right that my post for parameter FILES is wrong, it should be ["C:\Users\pk3100\Downloads\logo.gif"] or [r"C:\Users\pk3100\Downloads\logo.gif"]. Sorry for the confusing and inconvenience.

At that moment, I guess the issue is caused from FILES parameter so I tried different ways to transfer this parameter. But now I suppose it should be caused by the called RFC/BAPI. This BAPI is not callable remotely. But I can't do the testing since I am not granted to modify SAP standard BAPI.

Thanks!

bsrdjan commented 10 months ago

This BAPI is not callable remotely. But I can't do the testing since I am not granted to modify SAP standard BAPI.

Standard BAPI should not be modified but you can create custom ("Z") function module, RFC enabled, with exactly the same signature as non RFC-enabled function module. Then inside your RFC-enabled function module, call the non RFC enabled function. Some call it BAPI "wrapper"