Introduction
This handout provides ready-to-use JCL examples to help you simulate controlled return codes and intentional abends, which are useful for testing COND, IF/THEN/ELSE, and error-handling logic in JCL procedures. These scenarios are commonly used during training and debugging.
The first example shows how to trigger a specific return code using a simple REXX script. This can help test how your JCL behaves when steps return various RC values.
The second example introduces a COBOL program designed to intentionally abend with a U4038 error, allowing you to observe how JCL handles abends within procedures or job steps.
The third example introduces a COBOL program designed to run for specific amount of time, allowing you to trigger time condition or even some time to longer running job to see sync issues.
Compiling and Running Cobol
Most training systems provide the IGYWCLG cataloged procedure procedure for compile-link-go, which includes steps to compile, link-edit, and execute a COBOL program.
In some cases, it is more efficient to use the IGYWCL procedure to compile and link-edit the program once, and then reuse only the GO step for repeated execution.
Both The proc may slightly differ from system to system depending on cobol version. if not available use the one in the link. If the proc is not available through concantenated library make sure to use JCLLIB ORDER=
Sample JCL to compile, link, and execute:
//COBCL1 EXEC IGYWCLG,SRC=U4038PGM
//COBOL.SYSIN DD *
<ANY Cobol code>
/*
Trigger return code using REXX
Use the following sample JCL to simulate different return codes. This will help create multi-step jobs with varying COND
logic.
Replace <Your ID>
with your training ID and <YOUR REXX EXEC>
with the dataset containing the RETRC
REXX member.
Create a dataset with RECFM=FB, LRECL=80, BLKSIZE=800
to store the REXX script named RETRC
. The script is provided below:
/* REXX RETURN EXPECTED RC */
PARSE ARG RETCD
SAY RETCD
IF DATATYPE(RETCD) <> 'NUM' THEN RETCD = 0
EXIT RETCD
Submitting the REXX to get the desired RC code (In Example RC=2).
//<YOUR ID>C JOB ,NOTIFY=&SYSUID
//COMBINE EXEC PGM=IRXJCL,PARM='RETRC 2'
//SYSEXEC DD DSN=<YOUR REXX EXEC>,DISP=SHR
//SYSTSIN DD DUMMY
//SYSTSPRT DD DSN=&&TEMPPS1,DISP=(NEW,PASS),
// DCB=(RECFM=FB,LRECL=80,BLKSIZE=80)
Trigger Abend using Cobol
To simulate abends such as U4038
, use the following COBOL program. This helps test COND=ONLY
and COND=EVEN
behaviors and various other scenarios.
CBL SSRANGE
IDENTIFICATION DIVISION.
PROGRAM-ID. U4038PGM.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-TABLE.
05 WS-ITEM PIC X(10) OCCURS 5 TIMES.
01 IDX PIC 9(3) VALUE 100.
PROCEDURE DIVISION.
MOVE 'CRASH' TO WS-ITEM(IDX)
DISPLAY 'You should not see this'
GOBACK.
Run the program for specific second
To simulate running program for specific time, use the following COBOL program. It takes SYSIN Numeric value and execute the application for specified seconds.
IDENTIFICATION DIVISION.
PROGRAM-ID. LOOPCBL.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-INPUT-CHAR PIC X(5).
01 WS-START-TIME PIC 9(8).
01 WS-CURRENT-TIME PIC 9(8).
01 WS-START-SECONDS PIC 9(9).
01 WS-CURRENT-SECONDS PIC 9(9).
01 WS-LAST-SECONDS PIC 9(9).
01 WS-ELAPSED-SECONDS PIC 9(4).
01 WS-INPUT-NUM PIC 9(5) COMP-3.
******************************************************************
PROCEDURE DIVISION.
100-MAIN.
ACCEPT WS-INPUT-CHAR
DISPLAY WS-INPUT-CHAR
COMPUTE WS-INPUT-NUM = FUNCTION NUMVAL(WS-INPUT-CHAR)
DISPLAY '>> Starting ' WS-INPUT-CHAR ' second loop...'
ACCEPT WS-START-TIME FROM TIME
DISPLAY WS-START-TIME
COMPUTE WS-START-SECONDS =
FUNCTION NUMVAL (WS-START-TIME(1:2)) * 3600 +
FUNCTION NUMVAL (WS-START-TIME(3:2)) * 60 +
FUNCTION NUMVAL (WS-START-TIME(5:2))
DISPLAY WS-START-SECONDS
MOVE WS-START-SECONDS TO WS-LAST-SECONDS
PERFORM UNTIL WS-ELAPSED-SECONDS >= WS-INPUT-NUM
ACCEPT WS-CURRENT-TIME FROM TIME
COMPUTE WS-CURRENT-SECONDS =
FUNCTION NUMVAL (WS-CURRENT-TIME(1:2)) * 3600 +
FUNCTION NUMVAL (WS-CURRENT-TIME(3:2)) * 60 +
FUNCTION NUMVAL (WS-CURRENT-TIME(5:2))
COMPUTE WS-ELAPSED-SECONDS =
WS-CURRENT-SECONDS - WS-START-SECONDS
IF WS-CURRENT-SECONDS > WS-LAST-SECONDS THEN
DISPLAY WS-CURRENT-SECONDS
MOVE WS-CURRENT-SECONDS TO WS-LAST-SECONDS
END-IF
END-PERFORM
DISPLAY '>> Starting ' WS-INPUT-CHAR ' second ends...'
**********************************
STOP RUN.
/*