IBM Support

How to find the JOB name using a COBOL program.

Troubleshooting


Problem

Within an Enterprise COBOL for z/OS program, how does one discover the name of the job? //MYJOB JOB (12345,6789),'MR. PROGRAMMER' In this example, I want to extract the job name which is MYJOB.

Environment

z/OS IBM mainframes.

Resolving The Problem

IDENTIFICATION DIVISION.    
PROGRAM-ID. JOBNAME.  
ENVIRONMENT DIVISION.
DATA DIVISION.  
LOCAL-STORAGE SECTION.
77 PSAAOLD-PTR        USAGE POINTER.
77 PSAAOLD-ADDR       REDEFINES PSAAOLD-PTR PIC S9(9) BINARY.
77 ASCB-PTR           USAGE POINTER.
77 ASCB-ADDR          REDEFINES ASCB-PTR    PIC S9(9) BINARY.
77 JOBNAME-PTR        USAGE POINTER.
77 JOBNAME-ADDR       REDEFINES JOBNAME-PTR PIC S9(9) BINARY.
LINKAGE SECTION.  
77 A-PTR              USAGE POINTER.
77 JOBNAME-CHARS      PIC X(8).    
PROCEDURE DIVISION.
*    GET OUR ASCB ADDRESS FROM THE PSA    
    MOVE 548 TO PSAAOLD-ADDR.    
    SET ADDRESS OF A-PTR TO PSAAOLD-PTR.
    SET ASCB-PTR TO A-PTR.  
*    ASCBJBNI  
    COMPUTE JOBNAME-ADDR = ASCB-ADDR + 172.
    SET ADDRESS OF A-PTR TO JOBNAME-PTR.  
    SET JOBNAME-PTR TO A-PTR.    
    IF JOBNAME-PTR IS NOT EQUAL NULL THEN
        SET ADDRESS OF JOBNAME-CHARS TO JOBNAME-PTR          
        DISPLAY "INITIATED JOBNAME IS " JOBNAME-CHARS        
    END-IF.                                                  
*    ASCBJBNS    
    COMPUTE JOBNAME-ADDR = ASCB-ADDR + 176.
    SET ADDRESS OF A-PTR TO JOBNAME-PTR.  
    SET JOBNAME-PTR TO A-PTR.  
    IF JOBNAME-PTR IS NOT EQUAL NULL THEN                    
        SET ADDRESS OF JOBNAME-CHARS TO JOBNAME-PTR          
        DISPLAY "START/MOUNT/LOGON JOBNAME IS " JOBNAME-CHARS
    END-IF.
    GOBACK.
The result is in JOBNAME-CHARS.
If this executes as a batch job, then the result will be
INITIATED JOBNAME IS MYJOB      
START/MOUNT/LOGON JOBNAME IS INIT

If this executes from TSO's READY prompt, the userid will be found. Assuming your userid is ABC123, the result will be
 START/MOUNT/LOGON JOBNAME IS ABC123.

[{"Product":{"code":"SS6SG3","label":"Enterprise COBOL for z\/OS"},"Business Unit":{"code":"BU011","label":"Systems - zSystems"},"Component":"Runtime","Platform":[{"code":"PF035","label":"z\/OS"}],"Version":"4.1","Edition":""}]

Document Information

Modified date:
08 August 2018

UID

swg21392963