If this is indeed JMR from CA, the product 'use to' provide the same interface your attempting to create.
The JMRSCAN examples I show appears to need to know how its being called, from ISPF TSO or batch, there was, and maybe still is a check in the JMR main rexx to do this checking, once the environment was know to JMR these values were passed to the program as a parm. If you have JMR look to see if there is a JMRMAINT rexx or clist, there is an example of how to correctly check the environment and call the program.