#-Begin-----------------------------------------------------------------
#-Packages--------------------------------------------------------------
from ctypes import *
#-Structures------------------------------------------------------------
class RFC_ERROR_INFO(Structure):
_fields_ = [("code", c_long),
("group", c_long),
("key", c_wchar * 128),
("message", c_wchar * 512),
("abapMsgClass", c_wchar * 21),
("abapMsgType", c_wchar * 2),
("abapMsgNumber", c_wchar * 4),
("abapMsgV1", c_wchar * 51),
("abapMsgV2", c_wchar * 51),
("abapMsgV3", c_wchar * 51),
("abapMsgV4", c_wchar * 51)]
class RFC_CONNECTION_PARAMETER(Structure):
_fields_ = [("name", c_wchar_p),
("value", c_wchar_p)]
#-Constants-------------------------------------------------------------
RFC_OK = 0
#-Main------------------------------------------------------------------
ErrInf = RFC_ERROR_INFO; RfcErrInf = ErrInf()
ConnParams = RFC_CONNECTION_PARAMETER * 5; RfcConnParams = ConnParams()
SAPNWRFC = "sapnwrfc.dll"
SAP = windll.LoadLibrary(SAPNWRFC)
#-Prototypes------------------------------------------------------------
SAP.RfcOpenConnection.argtypes = [POINTER(ConnParams), c_ulong, \
POINTER(ErrInf)]
SAP.RfcOpenConnection.restype = c_void_p
SAP.RfcCloseConnection.argtypes = [c_void_p, POINTER(ErrInf)]
SAP.RfcCloseConnection.restype = c_ulong
SAP.RfcGetFunctionDesc.argtypes = [c_void_p, c_wchar_p, POINTER(ErrInf)]
SAP.RfcGetFunctionDesc.restype = c_void_p
SAP.RfcCreateFunction.argtypes = [c_void_p, POINTER(ErrInf)]
SAP.RfcCreateFunction.restype = c_void_p
SAP.RfcInvoke.argtypes = [c_void_p, c_void_p, POINTER(ErrInf)]
SAP.RfcInvoke.restype = c_ulong
SAP.RfcDestroyFunction.argtypes = [c_void_p, POINTER(ErrInf)]
SAP.RfcDestroyFunction.restype = c_ulong
SAP.RfcPing.argtypes = [c_void_p, POINTER(ErrInf)]
SAP.RfcPing.restype = c_ulong
#-Connection parameters-------------------------------------------------
RfcConnParams[0].name = "ASHOST"; RfcConnParams[0].value = "ABAP"
RfcConnParams[1].name = "SYSNR" ; RfcConnParams[1].value = "00"
RfcConnParams[2].name = "CLIENT"; RfcConnParams[2].value = "001"
RfcConnParams[3].name = "USER" ; RfcConnParams[3].value = "BCUSER"
RfcConnParams[4].name = "PASSWD"; RfcConnParams[4].value = "minisap"
hRFC = SAP.RfcOpenConnection(RfcConnParams, 5, RfcErrInf)
if hRFC != None:
#-Variant 1-----------------------------------------------------------
hFuncDesc = SAP.RfcGetFunctionDesc(hRFC, "RFC_PING", RfcErrInf)
if hFuncDesc != 0:
hFunc = SAP.RfcCreateFunction(hFuncDesc, RfcErrInf)
if hFunc != 0:
if SAP.RfcInvoke(hRFC, hFunc, RfcErrInf) == RFC_OK:
print("Ping successful")
else:
print("Ping not successful")
rc = SAP.RfcDestroyFunction(hFunc, RfcErrInf)
#-Variant 2-----------------------------------------------------------
if SAP.RfcPing(hRFC, RfcErrInf) == RFC_OK:
print("Ping successful")
else:
print("Ping not successful")
rc = SAP.RfcCloseConnection(hRFC, RfcErrInf)
else:
print(RfcErrInf.key)
print(RfcErrInf.message)
del SAP
#-End-------------------------------------------------------------------
#-Begin-----------------------------------------------------------------
#-Packages--------------------------------------------------------------
from ctypes import *
#-Structures------------------------------------------------------------
class RFC_ERROR_INFO(Structure):
_fields_ = [("code", c_long),
("group", c_long),
("key", c_wchar * 128),
("message", c_wchar * 512),
("abapMsgClass", c_wchar * 21),
("abapMsgType", c_wchar * 2),
("abapMsgNumber", c_wchar * 4),
("abapMsgV1", c_wchar * 51),
("abapMsgV2", c_wchar * 51),
("abapMsgV3", c_wchar * 51),
("abapMsgV4", c_wchar * 51)]
class RFC_CONNECTION_PARAMETER(Structure):
_fields_ = [("name", c_wchar_p),
("value", c_wchar_p)]
#-Constants-------------------------------------------------------------
RFC_OK = 0
#-Main------------------------------------------------------------------
ErrInf = RFC_ERROR_INFO; RfcErrInf = ErrInf()
ConnParams = RFC_CONNECTION_PARAMETER * 5; RfcConnParams = ConnParams()
SAPNWRFC = "sapnwrfc.dll"
SAP = windll.LoadLibrary(SAPNWRFC)
#-Prototypes------------------------------------------------------------
SAP.RfcOpenConnection.argtypes = [POINTER(ConnParams), c_ulong, \
POINTER(ErrInf)]
SAP.RfcOpenConnection.restype = c_void_p
SAP.RfcCloseConnection.argtypes = [c_void_p, POINTER(ErrInf)]
SAP.RfcCloseConnection.restype = c_ulong
SAP.RfcGetFunctionDesc.argtypes = [c_void_p, c_wchar_p, POINTER(ErrInf)]
SAP.RfcGetFunctionDesc.restype = c_void_p
SAP.RfcCreateFunction.argtypes = [c_void_p, POINTER(ErrInf)]
SAP.RfcCreateFunction.restype = c_void_p
SAP.RfcInvoke.argtypes = [c_void_p, c_void_p, POINTER(ErrInf)]
SAP.RfcInvoke.restype = c_ulong
SAP.RfcDestroyFunction.argtypes = [c_void_p, POINTER(ErrInf)]
SAP.RfcDestroyFunction.restype = c_ulong
SAP.RfcGetStructure.argtypes = [c_void_p, c_wchar_p, \
POINTER(c_void_p), POINTER(ErrInf)]
SAP.RfcGetStructure.restype = c_ulong
SAP.RfcGetChars.argtypes = [c_void_p, c_wchar_p, c_void_p, c_ulong, \
POINTER(ErrInf)]
SAP.RfcGetChars.restype = c_ulong
#-Connection parameters-------------------------------------------------
RfcConnParams[0].name = "ASHOST"; RfcConnParams[0].value = "ABAP"
RfcConnParams[1].name = "SYSNR" ; RfcConnParams[1].value = "00"
RfcConnParams[2].name = "CLIENT"; RfcConnParams[2].value = "001"
RfcConnParams[3].name = "USER" ; RfcConnParams[3].value = "BCUSER"
RfcConnParams[4].name = "PASSWD"; RfcConnParams[4].value = "minisap"
hRFC = SAP.RfcOpenConnection(RfcConnParams, 5, RfcErrInf)
if hRFC != None:
hFuncDesc = SAP.RfcGetFunctionDesc(hRFC, "RFC_SYSTEM_INFO", RfcErrInf)
if hFuncDesc != 0:
hFunc = SAP.RfcCreateFunction(hFuncDesc, RfcErrInf)
if hFunc != 0:
if SAP.RfcInvoke(hRFC, hFunc, RfcErrInf) == RFC_OK:
hStruct = c_void_p(0)
if SAP.RfcGetStructure(hFunc, "RFCSI_EXPORT", hStruct, \
RfcErrInf) == RFC_OK:
SAPHost = create_unicode_buffer(8 + 1)
rc = SAP.RfcGetChars(hStruct, "RFCHOST", SAPHost, 8, \
RfcErrInf)
print(SAPHost.value)
SAPSysID = create_unicode_buffer(8 + 1)
rc = SAP.RfcGetChars(hStruct, "RFCSYSID", SAPSysID, 8, \
RfcErrInf)
print(SAPSysID.value)
SAPDBHost = create_unicode_buffer(32 + 1)
rc = SAP.RfcGetChars(hStruct, "RFCDBHOST", SAPDBHost, 32, \
RfcErrInf)
print(SAPDBHost.value)
SAPDBSys = create_unicode_buffer(10 + 1)
rc = SAP.RfcGetChars(hStruct, "RFCDBSYS", SAPDBSys, 10, \
RfcErrInf)
print(SAPDBSys.value)
rc = SAP.RfcDestroyFunction(hFunc, RfcErrInf)
rc = SAP.RfcCloseConnection(hRFC, RfcErrInf)
else:
print(RfcErrInf.key)
print(RfcErrInf.message)
del SAP
#-End-------------------------------------------------------------------
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
6 | |
5 | |
4 | |
4 | |
4 | |
4 | |
3 | |
2 | |
2 |