So, the problem was that the procedure that was calling the GetWork proc did not have parms passed to it in the right order. The call to getwork is the third level of nested call (if I can call it so). The fact that the error was happening at this unsuspicious line made things confusing.