MainframeSupports
tip week 47/2019:

Sometimes an application requires you to access the jobname of the job your program is being executed by. There are many ways to access the jobname and I have previously indirectly written about it. The jobname is actually located in the control block called TIOT. Long ago most installations implemented a program (typically written in assembler) to access the jobname. The problem is that the program is so old that no one knows about it any more.

The strange thing is you can actually access the jobname using a JCL-variable named &JOBNAME. This variable has been available since z/OS version 2.1. However there are some challenges when using this variable. Please start by trying the following example before you use it for good:

//WEEKTIP JOB ,'WEEKTIP',NOTIFY=&SYSUID        
//*                                              
// EXPORT SYMLIST=*                              
// SET MYJOB=&JOBNAME                            
//*                                              
//COPY     EXEC PGM=IEFBR14,PARM='&JOBNAME'      
//*                                              
//COPY     EXEC PGM=IEBGENER                     
//SYSUT1   DD *,SYMBOLS=EXECSYS                  
JOBNAME=&JOBNAME                                 
MYJOB=&MYJOB                                     
//SYSUT2   DD SYSOUT=*                           
//SYSIN    DD DUMMY

When you have executed the above job (which most likely will require changes to the job card to work for you) you need to take a closer look at the job output. After SET MYJOB=&JOBNAME you can see which value MYJOB has. To your and my surprise you will discover MYJOB has the value JES2. It is the same when you use &JOBNAME in the PARM-field. Now take a look at the output for DD name SYSOUT2. It will look like:

JOBNAME=WEEKTIP
MYJOB=JES2

Now JOBNAME finally has the value we are interested in. In other words, if you want to use the JCL-variable &JOBNAME you need to specify it in some kind of SYSIN and then read the value into your program. Or you can use it directly in your SYSIN to be part of some SQL or DB2 utility input or ... The possibilities are many when you finally get the idea. Please observe that you need to specify the JCL-parameter SYMBOLS=EXECSYS on your SYSIN-card to get access to the value of &JOBNAME.

And why is it that &JOBNAME has one value in SYSIN and another outside. This is because JES2 is in control when the JCL is scanned, but because of the parameter SYMBOLS=EXECSYS JES2 will postpone the scanning of your SYSIN until the job is actually executing and then &JOBNAME has to be the name of your job.

Previous tip in english        Forrige danske tip        Tip list