In week 25/2007 I described how to execute TSO commands from COBOL and PL/I. When doing so in batch your program is required to run in TSO using program IKJEFT01. I think it will be much more elegant if I am able to use EXEC PGM=MYTSOPGM instead of EXEC PGM=IKJEFT01 and still be able to use TSO commands.
To my surprise a little research revealed that it is indeed possible to execute TSO commands without using IKJEFT01. A module called TSOENV starts the TSO command processor a makes it available for your executing program. When TSOENV has been called once you may execute as many TSO commands as you like using TSOLNK and it works just as good as when you use IKJEFT01 as the main program.
Execute TSOENV from COBOL like this:
In PL/I it is just as simple:
If RETURN-CODE or PLIRETV() is not equal to zero it may very well be because the TSO command processor is already established and you are already ready to call TSOLNK without any problems. In fact you may code all your TSO command executing programs with a call to TSOENV and just ignore the return code. Then your TSO commands will always work and you do not have to worry about whether IKJEFT01 was invoked or not.
I have a strong feeling telling me that there are limits to the amount of TSO commands which will work when the TSO command processor has been invoked using TSOENV. I have not tried RACF commands or HSM commands and I am not sure they will work. Until now I have only used the commands described in the TSO command reference and they work fine.