Hi Raf,
Can't you simply check available stock before calling transaction in your abap code (simple selection on table MARD, depending what you allocate as available for STO ) and then pass the right value into call transaction parameters (assuming the qty is there)?
BR,
Tomek