Search code examples
coboljcl

Passing SYSUID and JOB ID as parameter to COBOL program through JCL


I need to pass the SYSUID and JOBID to the cobol program for logging purpose, how is this possible?,

can the same be passed as an input for a query in a JCL.

Thanks in advance.


Solution

  • SYSUID is simple, you just add it to the PARM parameter of your EXEC statement.

    //ASTEP EXEC PGM=A#PGM,PARM='&SYSUID'
    

    JOBID isn't available as a parameter. You will have to write COBOL code to chain through z/OS control blocks (see the Data Areas books at that link) if you need it. This can be done, but I don't recommend it.

    If you actually want to get the job number, you write code to go to the PSA control block, which is at relative memory location 0. From there you get a pointer to the current TCB which is in the PSATOLD field of the PSA, from the TCB you get the TCBJSCBB field which is a pointer to the JSCB, from the TCBJSCBB fielf in the JSCB you get a pointer to the SSIB which contains the SSIBJBID field which is the job number. All of these control blocks, PSA, TCB, JSCB, and SSIB are documented (for z/OS 2.4) at the link above. And I reiterate that I don't recommend doing this.

    There's a tutorial on chaining through z/OS control blocks in two parts from Longpela.