Run COBOL + DB2 Batch with DSN and IKJEFT01

Running a COBOL DB2 batch program is more than EXEC PGM=yourmodule. The job must start the TSO Terminal Monitor Program, connect to Db2 with DSN, and RUN the program under the correct plan and libraries. This tutorial shows the prerequisites, JCL pattern, verification checks, and common first-run failures.

Hands-on batch run
Progress0 of 0 lessons

Why batch COBOL uses DSN RUN

Most Db2 batch applications run under the TSO Terminal Monitor Program in background mode. IKJEFT01 reads SYSTSIN commands, starts a DSN session for a subsystem, and the RUN subcommand loads your COBOL program in that Db2-connected environment. The plan named on RUN is the allocation unit that locates packages for the SQL your program issues.

Directly executing the COBOL module without DSN can work only in attachment models designed for that path. For classic TSO/batch Db2 COBOL, DSN RUN is the standard and safest teaching pattern.

Prerequisites

Batch run readiness checks
AreaWhat to verify
BuildCurrent load module built from the same precompile as the bound DBRM/package.
BindPackage exists in the expected collection and the plan PKLIST can find it.
LibrariesSDSNEXIT, SDSNLOAD, application loadlib, and any exit or runtime libraries.
AuthorizationJob USER or associated auth ID can execute the plan and access required data.
FilesAll application DD names allocated: input, output, work, and sort files as needed.

Also confirm commit strategy, restart checkpoints, and whether the job should stop on the first negative SQLCODE. A batch program that ignores SQLCODE can update partial data and still look “successful” in SDSF if it sets return code zero.

RUN command options

Common DSN RUN options for batch COBOL
OptionPurpose
SYSTEM(ssid)Connects DSN to the Db2 subsystem or group attach name
PROGRAM / PROGNames the application load module to run
PLANNames the application plan used for Db2 allocation
LIBLibrary containing the application program
PARMSPasses Language Environment and/or application parameters

Steps: run the batch program

1. Assemble the JCL skeleton

Start with IKJEFT01, include Db2 libraries, allocate SYSTSPRT and SYSTSIN, and add every DD your COBOL program expects. Use DYNAMNBR when your shop standard includes it for DSN workloads.

jcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//EMPBATCH JOB (ACCT),'EMPRPT',CLASS=A,MSGCLASS=X,NOTIFY=&SYSUID //*---------------------------------------------------------------* //* Run COBOL Db2 batch program EMPRPT01 under plan TRAINPLN //*---------------------------------------------------------------* //GO EXEC PGM=IKJEFT01,DYNAMNBR=20,REGION=0M //STEPLIB DD DISP=SHR,DSN=DSN.V12R1M0.SDSNEXIT // DD DISP=SHR,DSN=DSN.V12R1M0.SDSNLOAD // DD DISP=SHR,DSN=APP.TRAIN.LOADLIB //SYSTSPRT DD SYSOUT=* //SYSOUT DD SYSOUT=* //SYSPRINT DD SYSOUT=* //EMPIN DD DISP=SHR,DSN=APP.TRAIN.EMPIN //EMPOUT DD SYSOUT=* //SYSTSIN DD * DSN SYSTEM(DB2T) RUN PROGRAM(EMPRPT01) - PLAN(TRAINPLN) - LIB('APP.TRAIN.LOADLIB') - PARMS('/DEPT=A10') END /*

2. Match PLAN and PROGRAM to the bind

PROGRAM must be the load module name. PLAN must be the plan that lists the collection containing package EMPRPT01. If your site uses multiple environments, double-check that the job is not pointing a production load module at a test plan, or the reverse.

3. Pass PARMS deliberately

The example uses a slash before application parameters, which is a common way to separate Language Environment runtime options from program arguments. If your program expects a different layout, follow its runbook. Never copy PARMS from an unrelated sample without reading the COBOL linkage section.

4. Keep the DSN step focused

IBM guidance is to keep DSN job steps short. If the application abends or returns a non-zero code, DSN typically terminates. Put unrelated utility work in separate steps so a Db2 application failure does not obscure later processing.

Verify results

  • Confirm IKJEFT01 and application return codes in the job log.
  • Read SYSTSPRT for DSN messages and RUN completion text.
  • Inspect application SYSOUT for SQLCODE handling, record counts, and business totals.
  • For updates, query a known key before and after, or reconcile input count to rows changed.
  • On failure, capture PLAN, PROGRAM, LIB, subsystem, and the first negative SQLCODE before changing multiple things at once.
sql
1
2
3
4
5
-- Example post-run reconciliation for a reporting extract key SELECT COUNT(*) AS EMP_COUNT FROM TRAINING.EMPLOYEE WHERE DEPT_CODE = 'A10' AND ACTIVE_FLAG = 'Y';

Common errors

Frequent COBOL Db2 batch run problems
SymptomLikely causeCorrective action
Module not found / IKJ56500I style failureWrong STEPLIB/JOBLIB/LIB or misspelled PROGRAM nameVerify the load library membership and the exact module name.
SQLCODE -805Plan/package mismatch or missing collection on PKLISTCompare RUN PLAN, SYSPACKLIST, and SYSPACKAGE for the consistency token.
SQLCODE -818Load module and package timestamps disagreeRebuild and rebind from one precompile generation, then rerun.
SQLCODE -922 / connection failureWrong subsystem, Db2 not available, or attachment authorization problemConfirm SYSTEM name, Db2 status, and job authorization to connect.
Abend or non-zero RC ends DSN earlyApplication error, missing DD, or unhandled SQLCODEFix the program or JCL, keep DSN steps short, and rerun a controlled test.

Missing application DD names often surface as language-environment or COBOL file status problems before any SQL runs. When SQL never starts, check file allocations first. When SQL starts and fails immediately, check plan, package, and authorization next.

Explain It Like I'm Five

Think of IKJEFT01 as a helper who walks your COBOL robot to the Db2 school office. DSN SYSTEM opens the right school building. RUN PROGRAM tells which robot to start. PLAN is the hall pass that lists which binders of answers the robot may use. If the hall pass is wrong, the robot can stand up and still be told it may not open the binder.

Exercises

  1. Write a DSN RUN command for program ORDUPD01, plan ORDPLAN, and library APP.PROD.LOADLIB.
  2. List five DD statements a payroll extract program might need in addition to SYSTSIN.
  3. Explain why a job can show IKJEFT01 RC=0 while business totals are wrong.
  4. Create a failure checklist for SQLCODE -805 versus -818 in batch.
  5. Describe how you would prove the batch job used the intended Db2 subsystem in a data sharing group.

Quiz

Test Your Knowledge

1. Which program is commonly used to run a COBOL Db2 batch job under TSO?

  • DSNUTILB
  • IKJEFT01
  • DFSORT
  • IDCAMS

2. What does the DSN RUN PLAN option identify?

  • The tablespace buffer pool
  • The application plan that allocates Db2 resources and locates packages
  • The SPUFI input member
  • The CICS DB2CONN name

3. Where should the COBOL load module usually be found?

  • Only in SYS1.PARMLIB
  • In STEPLIB/JOBLIB or the LIB keyword library on the RUN command
  • Only inside the DBRM library
  • Only in the bootstrap dataset

4. What happens if DSN receives a non-zero return code from the application?

  • DSN always continues with the next SYSTSIN command
  • DSN typically terminates the session
  • Db2 automatically rebinds the package
  • The job converts to SPUFI

5. A batch program gets SQLCODE -805. What should you check first?

  • Only the printer class
  • Whether the RUN PLAN and package collection match the bound application
  • Only the REGION size
  • Only the TIME parameter

Frequently Asked Questions