batch mainframe job number available to natural program ?

Is there a system variable holding the job number for jcl submitted to run natural program in batch on the mainframe?
I use *init-user for the job name, but how can I capture the job number?

thanks,

John

The job number is not available to Natural.

Well, let’s just say it’s not available via Natural facilities.

However, it is easy to get it via an assembler program. You can find examples of the control block chain in several programs at the CBT Tape (think mainframe shareware) site - http://www.cbttape.org.

Do you have Entire System Server (NPR)? The job number can be obtained from it. JOB-NUMBER is found in the following NPR files:

ACTIVE-JOBS
READ-SPOOL
SPOOL-FILES
SPOOL-QUEUE
SPOOL-UPDATE
SUBMIT
TASK-INFO
WRITE-SPOOL

We “mine” the job number via:

… jcl
//GETJOBNO EXEC PROC=GETJOBNO

which is SYS3.PROCLIB(GETJOBNO):

000001 //GETJOBNO PROC
000002 //GETJOBNO EXEC PGM=IKJEFT1B,PARM=‘GETJOBNO’
000003 //SYSTSPRT DD DSN=&&JOBNO,DISP=(NEW,PASS),SPACE=(TRK,1),UNIT=SYSDA
000004 //SYSPROC DD DISP=SHR,DSN=SYS3.CTM.PROD.CNTL
000005 //SYSTSIN DD DUMMY

Which runs rex script:

/* REXX

This REX program will return the Job No of the currently executing
job. It is used when you want to log job run infomation in file
JOB-LOG. If you use “BATCHON JOB LOG” then you must put the
following JCL step before Natural step:

 //JOBNO    EXEC PROC=GETJOBNO

You then need to supply the following workfile into your Natural:

 //CMWKF32  DD DSN=&&JOBNO,DISP=SHR

and then PASREG JOB LOG will create a new record on JOB-LOG for
your job name and job number, it will also set the AIV variable:

 +JOB-NUMBER          (P5)

During the execution of your natural programs you can the callnat
ZJOBLOG to record details about the program execution. At the end
when BATCTOFF is executed it will create the final JOB LOG record
You can inspect your jobs via ZJOBLOGP.

Written by Paul Macgowan for PSS 25/1/08
*/
tcb = storage(21c,4)
jscb = storage(d2x(c2d(tcb)+180),4)
ssib = storage(d2x(c2d(jscb)+316),4)
jobnum = storage(d2x(c2d(ssib)+12),8)
say jobnum

Our Natural code then reads WF32 via a standard BATCHON program

//CMSYNIN DD *
LOGON
BATCHON TEST X

BATCHON is:

DEFINE DATA INDEPENDENT
1 +JOBLOG-JOB-NO (P5)

1 #JOBLINE (A20)
1 REDEFINE #JOBLINE
2 FILLER 1X
2 #JOB-KEYWORD (A3)
2 #JOB-NUMBER (N5)
2 #JOB-SEP (A1)
2 #JOB-RUN-NO (N6)

READ WORK 32 #JOBLINE
IF #JOB-KEYWORD = ‘JOB’ THEN
+JOBLOG-JOB-NO := #JOB-NUMBER
ESCAPE BOTTOM
END-IF
END-WORK
CLOSE WORK 32

So +JOBLOG-JOB-NO AIV will have the job No