I remember doing this many years ago. I seem to recall using the RCVMSG command to retrieve the last messages that were written to the joblog to retrieve the commands. Bear in mind that this may not work if you have no logging for your job.
Otherwise you could write your commands that you execute via QCMDEXC to a file, data queue, user space, etc and retrieve them yourself in your program.
In order to <F9=Retrieve> commands, you must either save each command that comes into your program in an array or file, or you must have the user’s job running at a LOG() level that supports automatic saving of commands.
If you store them yourself, then you retrieve them in whatever way you want.
If you have the system store them, then you use RCVMSG or the QMHRCVPM API to receive *REQUEST messages from the job’s external message queue. If the user’s job has an inappropriate logging level, then the command was never stored for you to retrieve. You’ll have to decide if you want to retrieve job attributes when your program starts, change the LOG() if necessary, and reset it back to the original before your program ends.