-
Notifications
You must be signed in to change notification settings - Fork 131
/
trfc_test.py
76 lines (54 loc) · 1.85 KB
/
trfc_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from pyrfc import RCStatus, Server
def handle_rfc(request_context=None, RESTART_QNAME="", TCPICDAT=[]):
context = (
{"error": "No request context"}
if request_context is None
else request_context["server_context"]
)
print("Python function: stfc_write_to_tcpic", f"context {context}")
return {"TCPICDAT": TCPICDAT}
def onCheckTransaction(rfcHandle, tid):
print("Executed onCheckTransaction Python function", rfcHandle, tid)
return RCStatus.OK
def onCommitTransaction(rfcHandle, tid):
print("Executed onCommitTransaction Python function", rfcHandle, tid)
return RCStatus.OK
def onConfirmTransaction(rfcHandle, tid):
print("Executed onConfirmTransaction Python function", rfcHandle, tid)
return RCStatus.OK
def onRollbackTransaction(rfcHandle, tid):
print("Executed onRollbackTransaction Python function", rfcHandle, tid)
return RCStatus.OK
# Create server
server = Server(
server_params={"dest": "MME_GATEWAY"},
client_params={"dest": "MME"},
config={"check_date": False, "check_time": False, "server_log": True},
)
# ABAP function used to send IDocs via tRFC/qRFC
server.add_function("STFC_WRITE_TO_TCPIC", handle_rfc)
# Register the RFC transaction handlers.
server.transaction_rfc_init(
sysId="MME",
transactionHandler={
"check": onCheckTransaction,
"commit": onCommitTransaction,
"rollback": onRollbackTransaction,
"confirm": onConfirmTransaction,
},
)
try:
# Start server
server.start()
# Get server attributes
# print(server.get_server_attributes())
# Check transaction handlers
# print(server.transaction_handlers)
# print(server.transaction_handlers_count)
input("Press Enter to stop server...\n")
server.stop()
except Exception as ex:
print(ex)
finally:
# Shutdown server
server.close()