I'm using SAP function module L_TO_CANCEL
via pyrfc and python to cancel warehouse management replenishment transfer orders (TOs). This works fine for some TOs but for others (also replenishment) is give an error
Negative stock for storage type X not allowed.
While this is true the TO has not been worked. No removal of stock from source storage type yet. So cancelling should not cause negative stock in destination storage type which is what is indicated in the error msg in this case. However this is the issue or why I think there is an issue.
If I run L_TO_CANCEL from SE37 via SAP GUI passing same parameters I_LGNUM, I_TANUM, I_CANCL it does cancel the TO in question even when TO is same TO as RFC call was unable to cancel and received negative stock not allow msg for.
s = RfcConnection(sysrfc="QE2")
result = s.delete_to(lgnum="220", tanum="9592250", cancl="X", commit_work="X")
def delete_to(self, lgnum=None, tanum=None, solex=None, cancl=None, subst=None, qname=username, update_task=None, commit_work=None, t_ltap_cancl=None):
return_msg = None
assert (lgnum is not None and tanum is not None), "Warehouse number as lgnum and Transfer Order as tanum are required for function delete_to"
if cancl is None:
cancl = "X"
try:
if t_ltap_cancl is None:
return_msg = self.conn.call("L_TO_CANCEL",
I_LGNUM=lgnum,
I_TANUM=pad(tanum, 10, "0"),
I_CANCL=cancl)
elif t_ltap_cancl is not None:
return_msg = self.conn.call("L_TO_CANCEL",
I_LGNUM=lgnum,
I_TANUM=pad(tanum, 10, "0"),
T_LTAP_CANCL=t_ltap_cancl)
except pyrfc._exception.ABAPApplicationError as e:
if e.msg_class == "L3" and e.msg_number == "354":
return_msg = self.get_error_code(Language="EN", Area=e.msg_class, Message=e.msg_number)[0][0].replace("&", "{}".format(tanum))
else:
return_msg = self.get_error_code(Language="EN", Area=e.msg_class, Message=e.msg_number)
except pyrfc._exception.ABAPRuntimeError as e:
if e.msg_class == "L3" and e.msg_number == "037":
return_msg = self.get_error_code(Language="EN", Area=e.msg_class, Message=e.msg_number)[0][0].replace("&", "{}".format(e.msg_v1))
else:
return_msg = self.get_error_code(Language="EN", Area=e.msg_class, Message=e.msg_number)
except Exception as e:
return_msg = e
return return_msg