That’s difficult to do. You can use the REXX userid function if you’re running under an interactive TSO/E session, but falls down if you call your REXX in batch.
The only way I can think of is to use the REXX STORAGE function to hop through z/OS Control Blocks. Here’s some code that will do it for you:
ASCB_Addr = C2D(Storage(224,4)) /* Get address of ASCB */
/* --- First check ASCBJBNI for Jobname ----------------------- */
Interpret "JobAddr = Storage("D2X(ASCB_ADDR+172)",4)"
If C2D(JobAddr) = 0 Then
/* --- Not running in initiator, so get jobname from ASCBJBNS - */
Interpret "JobAddr = Storage("D2X(ASCB_ADDR+176)",4)"
Interpret "Job = Storage("C2X(JobAddr)",8)"
say "Jobname: " Job
This looks in the ASCBJBNI field for a jobname. If not there, goes to ASCBJBNS to get the Started Task name. You still need to ADDRESS TSO to use the STORAGE function.
You can also find out the JES JobID using the following REXX code:
TCB_Addr = C2D(Storage(21C,4)) /* Current TCB Addr */
JSCB_Addr = C2D(Storage(D2X(TCB_Addr+180),4)) /* JSCB Addr */
SSIB_Addr = C2D(Storage(D2X(JSCB_Addr+316),4)) /* SSIB Addr */
JobID = Storage(D2X(SSIB_Addr+12),8)
say "Jobid: " JobID
Hope this helps.