<i>Why does this not work correctly…</i>
There’s no way for us to know because you don’t show us the code that fails. Most likely it’s because the coding is incorrect.
My first guess would be that one or more variables is DCLed incorrectly. My second guess would be that the parms are sent incorrectly.