Summary -

In this topic, we explain about the first program/Hello world program compilation with detailed examples.

As discussed earlier, COBOL programs are two types based on the environment they are running -

  • Batch
  • Online

In this topic, we will see how a COBOL program is running in a batch environment.

How to run a COBOL program in a batch environment?

Below are the prerequisites to run a COBOL program in a mainframe environment -

  • A mainframe id.
  • A PDS (calls as SRCLIB or Source Library) to code the COBOL program.
  • A PDS (calls as LOADLIB or LOAD Library) for placing the LOAD module of the COBOL program after compilation.
  • [Optional, if required] A PDS ( calls as a COPYLIB ) to place external copybooks if using in the program.

Below are the steps to run the COBOL program in a mainframe environment -

  • Code COBOL program
  • Compile COBOL program
  • Run COBOL program

Coding COBOL program -

Login to the mainframe TSO environment, edit the PDS, and code the program like below -

Hello World Program

In this example, MATEGJ.COBOL.SRCLIB is the source library used to code the program and the program name is FIRSTPRG.

Note! The name specified with PROGRAM-ID is used as a program name to run the program. The module name and program name with PROGRAM-ID might not be the same. However, to avoid confusion, specify both names as the same. Refer to the below screenshot.
Hello World Program

Compile COBOL program -

There are many ways to compile the COBOL program. Version control tools like Endevor or Changeman are used to compile the COBOL program in a real-time environment.

Also, we can use standard JCL to compile the program. The compile JCL for the COBOL program are as follows -

COBOL program compilation JCL
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
//MATEGJC JOB (123),'MTH',CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1),            
//             NOTIFY=&SYSUID                                           
//********************************************************************
//*  COMPILE A COBOL PROGRAM                            
//********************************************************************
//COBOL  EXEC PGM=IGYCRCTL,REGION=0M,PARM=('LIB')                     
//STEPLIB  DD  DSNAME=IGY420.SIGYCOMP,                                
//             DISP=SHR                                               
//SYSIN    DD  DSN=MATEGJ.COBOL.SRCLIB(FIRSTPRG),DISP=SHR             
//SYSLIB   DD  DSN=MATEGJ.COPYLIB,DISP=SHR               
//SYSPRINT DD  SYSOUT=*                                               
//SYSLIN   DD  DSNAME=&&LOADSET,UNIT=SYSALLDA,                        
//             DISP=(MOD,PASS),SPACE=(TRK,(3,3)),                     
//             DCB=(BLKSIZE=3200)                                     
//SYSUT1   DD  UNIT=SYSALLDA,SPACE=(CYL,(1,1))                        
//SYSUT2   DD  UNIT=SYSALLDA,SPACE=(CYL,(1,1))                        
//SYSUT3   DD  UNIT=SYSALLDA,SPACE=(CYL,(1,1))                        
//SYSUT4   DD  UNIT=SYSALLDA,SPACE=(CYL,(1,1))                        
//SYSUT5   DD  UNIT=SYSALLDA,SPACE=(CYL,(1,1))                        
//SYSUT6   DD  UNIT=SYSALLDA,SPACE=(CYL,(1,1))                        
//SYSUT7   DD  UNIT=SYSALLDA,SPACE=(CYL,(1,1))                        
//********************************************************************
//*  LINK EDIT A COBOL PROGRAM                            
//********************************************************************
//LKED   EXEC PGM=IEWBLINK,COND=(8,LT,COBOL),REGION=0M                
//SYSLIB   DD  DSNAME=CEE.SCEELKED,DISP=SHR                           
//         DD  DSNAME=MATEGJ.LOADLIB,DISP=SHR            
//SYSPRINT DD  SYSOUT=*                                               
//SYSLIN   DD  DSNAME=&&LOADSET,DISP=(OLD,DELETE)                     
//         DD  DDNAME=SYSIN                                           
//SYSLMOD  DD  DSNAME=MATEGJ.LOADLIB(FIRSTPRG),DISP=OLD  
//SYSUT1   DD  UNIT=SYSALLDA,SPACE=(TRK,(10,10))                      
//SYSIN    DD  DUMMY                                                  
********************** BOTTOM OF DATA ********************************

However, we should know the library name where the compilation utilities IGYCRCTL and IEWBLINK are placed. For example - IGY420.SIGYCOMP for IGYCRCTL and CEE.SCEELKED for IEWBLINK in the above JCL.

Note! IGYCRCTL is the compilation utility to verify the syntax errors in the COBOL program.
IEWBLINK is the link editor used to linkedit the module output from the IGYCRCTL step and make it an executable load module.

Modify the highlighted libraries to their corresponding libraries and submit the JCL to compile the program.

Submit JCL

Once the MAXCC is 00(without warning or errors) or 04(with warnings), the COBOL program is compiled successfully.

Submit JCL Return Code

Executing COBOL program -

Submit the below JCL by specifying the program name and the load library to execute the program -

COBOL program RUN JCL
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
//MATEGJD JOB MSGLEVEL=(1,1),NOTIFY=&SYSUID                             
//**********************************************************************
//*  RUN A COBOL PROGRAM                                                
//**********************************************************************
//STEP01  EXEC PGM=FIRSTPRG                                             
//STEPLIB  DD  DSN=MATEGJ.LOADLIB,DISP=SHR                              
//SYSOUT   DD  SYSOUT=*                                                 
**************************** Bottom of Data ****************************
RUN JCL Submit

Once the MAXCC is 00(without warning or errors) or 04(with warnings), the COBOL program ran successfully.

RUN JCL Return Code

Check the output in SYSOUT of the SPOOL -

Program Output