Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
elif REQUTEXT == 'EXCEPTION_MESSAGE':
raise ABAPApplicationError(key='BAD_EXCEPTION_W_MSG',
msg_class='SR', # message id or class
msg_type='E', # out of e.g. 'E', 'A' or 'X'
msg_number='007', # 3 char numeric
msg_v1='V1 text' # 50 char
)
elif REQUTEXT == 'MESSAGE':
raise ABAPRuntimeError(
msg_class='SM', # message id or class
msg_type='E', # out of e.g. 'E', 'A' or 'X'
msg_number='107', # 3 char numeric string
msg_v1='V1 text (ABAP_MESSAGE)'
)
elif REQUTEXT == 'FAILURE':
raise ExternalRuntimeError("Something very bad happened.")
elif REQUTEXT == 'INVALID':
raise RFCError("Invalid exception")
return {
'ECHOTEXT': REQUTEXT,
'RESPTEXT': u"Local (raise error) server here. Use the following values"
u"for REQUTEXT: EXCEPTION, EXCEPTION_MESSAGE, MESSAGE, "
self.assertEqual(run.exception.msg_v1, "V1 text")
with self.assertRaises(ABAPRuntimeError) as run:
test.invoke_srv_function("STFC_CONNECTION", REQUTEXT="MESSAGE")
self.assertEqual(run.exception.code, 4, "rc")
self.assertEqual(run.exception.msg_class, "SM")
self.assertEqual(run.exception.msg_type, "E")
self.assertEqual(run.exception.msg_number, "107")
self.assertEqual(run.exception.msg_v1, "V1 text (ABAP_MESSAGE)")
with self.assertRaises(ExternalRuntimeError) as run:
test.invoke_srv_function("STFC_CONNECTION", REQUTEXT="FAILURE")
self.assertEqual(run.exception.code, 15, "rc")
self.assertEqual(run.exception.message[:9], "Something")
with self.assertRaises(ExternalRuntimeError) as run:
test.invoke_srv_function("STFC_CONNECTION", REQUTEXT="INVALID")
self.assertEqual(run.exception.code, 15, "rc")
self.assertEqual(run.exception.message[:7], "Invalid")
def test_ping(self):
assert self.conn.alive
self.conn.ping()
self.conn.close()
try:
self.conn.ping()
except pyrfc.ExternalRuntimeError as ex:
error = get_error(ex)
assert error["code"] == 13
assert error["key"] == "RFC_INVALID_HANDLE"
assert (
error["message"][0]
== "An invalid handle 'RFC_CONNECTION_HANDLE' was passed to the API call"
or error["message"][0] == "An invalid handle was passed to the API call"
)
def test_non_existing_field_table(self):
IMPORTSTRUCT = {"XRFCCHAR1": "A", "RFCCHAR2": "BC", "RFCCHAR4": "DEFG"}
try:
result = self.conn.call("STFC_STRUCTURE", RFCTABLE=[IMPORTSTRUCT])
except pyrfc.ExternalRuntimeError as ex:
assert ex.code == 20
assert ex.key == "RFC_INVALID_PARAMETER"
assert ex.message == "field 'XRFCCHAR1' not found"