Conditional JCL IF THEN ELSE Constructs |
The SimoTime Home Page |
This suite of programs provides an example of how mainframe JCL can do conditional processing and parameter passing. With JES/3 the conditional processing was improved to use "IF" statements. This JCL example will focus on the IF, THEN, ELSE and ENDIF statement constructs.
Both JCL examples will use a single COBOL program to process the parameter string provided by the JCL members. The COBOL program will also set various return codes prior to returning control back to JCL
The COBOL program is written using COBOL/2 dialect but also works with COBOL for MVS and COBOL/370. This suite of programs may serve as a tutorial for programmers that are new to COBOL and mainframe JCL and as a reference for experienced programmers. The JCL member is provided to run the jobs as an MVS batch jobs on an IBM mainframe or a distributed environment (Linux, Unix or Windows) using Micro Focus technologies.
Refer to http://www.microfocus.com for additional information.
We have made a significant effort to ensure the documents and software technologies are correct and accurate. We reserve the right to make changes without notice at any time. The function delivered in this version is based upon the enhancement requests from a specific group of users. The intent is to provide changes as the need arises and in a timeframe that is dependent upon the availability of resources.
Copyright © 1987-2025
SimoTime Technologies and Services
All Rights Reserved
The Job Entry System (JES) provides for conditional processing within a JCL member. When a job executes, a return code is set based on the status of execution. The return code can be a number between 0 (successful execution) to 4095 (non-zero shows error condition). The conventional or most commonly used values are as follows.
|
||||||||||||
Commonly used Return Code Values |
The Job Entry System (JES) uses two approaches to perform conditional processing within a JCL member. A job step execution can be controlled based on the return code of a previous step using the COND= parameter or the IF-THEN-ELSE construct that are explained in the following sections of this document.
Note: The preceding return codes are used by many of the utility programs that are provided on a Mainframe System. The values have been used as a guideline or convention for other third party software packages and user programs have adopted the convention.
The following is the mainframe JCL (JCLCONJ2.jcl) example that uses the IF, THEN, ELSE and ENDIF statement construct. The first step (NOPARM) will always execute and since there is no parameter specified the COBOL program (JCLCONC1.CBL) will simply set the return code to zero (0) and return to the JCL member.
The second step (COND00A) will always execute the COBOL program passing a parameter that will cause the COBOL program to set a Return-Code of zero (0). The third step (COND00B) will execute only if the return code from all the previous steps is zero (0). The JCL will then continue to execute testing various conditions as documented in the JCL member. The JOB statement will need to be modified for specific mainframe environments
//JCLCONJ2 JOB SIMOTIME,ACCOUNT,CLASS=1,MSGCLASS=0,NOTIFY=CSIP1 //JOBLIB DD DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR //* ******************************************************************* //* This JCL Member is provided by SimoTime Technologies * //* (C) Copyright 1987-2019 All Rights Reserved * //* Web Site URL: http://www.simotime.com * //* e-mail: helpdesk@simotime.com * //* ******************************************************************* //* //* Text - Process a parameter string passed from the JCL //* Author - SimoTime Technologies //* Date - January 24, 1996 //* //* This is a sample program that shows how a COBOL program can //* process input from the JCL using the PARM keyword from the EXEC //* statement. //* //* The COBOL program will set a condition and JCL will procees //* accordingly. //* //* This set of programs will run on a mainframe under MVS or on a //* Personal Computer with Windows and Micro Focus Mainframe Express //* //* ******************************************************************* //* Execute the COBOL program without a parameter. //* //NOPARM EXEC PGM=JCLCONC1 //* //* ******************************************************************* //* Execute the COBOL program with a parameter. //* Based on the PARM='parameter' the COBOL program will set the Return //* code to 0. //* //COND00A EXEC PGM=JCLCONC1,PARM='MSG-00 --- This is message zero...' //* // IF (RC EQ 0) THEN //COND00B EXEC PGM=JCLCONC1,PARM='COND00B - Return Code = 00...' // ELSE //COND00C EXEC PGM=JCLCONC1,PARM='COND00C - Unexpected Return Code...' // ENDIF //* //* The preceding step (COND00B) will be bypassed if CC is not equal //* to the Return Code (RC=0) of any of the preceding job steps. //* //* ******************************************************************* //* Execute the COBOL program with a parameter. //* Based on the PARM='parameter' the COBOL program will set the Return //* code to 4. //* //COND04A EXEC PGM=JCLCONC1,PARM='MSG-04 -- This is message four...' //* // IF (COND04A.RC EQ 4) THEN //COND04B EXEC PGM=JCLCONC1,PARM='COND04C - Return Code = 04...' // ELSE //COND04C EXEC PGM=JCLCONC1,PARM='COND04C - Unexpected Return Code...' // ENDIF //* //* The preceding step (COND04B) will be bypassed if CC is not equal //* to the Return Code (RC=4) of the preceding job step (COND04A). //* //* ******************************************************************* //* Execute the COBOL program with a parameter. //* Based on the PARM='parameter' the COBOL program will set the Return //* code to 8. //* //COND08A EXEC PGM=JCLCONC1,PARM='MSG-08 -- This is message eight...' //* // IF (COND08A.RC GT 7 AND RC LT 9) THEN //COND08B EXEC PGM=JCLCONC1, // PARM='COND08C - Return Code is GT 7 and LT 9...' // ELSE //COND08C EXEC PGM=JCLCONC1,PARM='COND08C - Unexpected Return Code...' // ENDIF //* //* The preceding step (COND08B) will be bypassed if CC is not equal //* to the Return Code (RC=8) of the preceding job step (COND08A). //* (COND08A). //* //* ******************************************************************* //* Execute the COBOL program with a parameter. //* // IF (RC EQ 0) THEN //EOJTEST1 EXEC PGM=JCLCONC1, // PARM='All Job Steps had a zero Return Code...' // ENDIF //* //* The preceding step (EOJTEST1) should be bypassed. //* // IF (RC LT 9) THEN //EOJTEST2 EXEC PGM=JCLCONC1, // PARM='All Job Steps had a Return Code of 0 through 8...' // ENDIF //* //* The preceding step (EOJTEST2) should execute. //* // IF (RC GT 8) THEN //EOJTEST3 EXEC PGM=JCLCONC1,COND=(9,GE), // PARM='Return Code greater than 8 for a job step.' // ENDIF //* //* The preceding step (EOJTEST3) should be bypassed. //*
This program (JCLCONC1.cbl) was written to be used as a teaching and learning aid. When a COBOL program is executed from a JCL member a data string (or parameter) may be passed from the JCL member to the COBOL program using the PARM keyword as follows
//JCLCONS2 EXEC PGM=JCLCONC1,PARM='datastring'
When the data string is passed from JCL to COBOL it is preceded with a two-byte binary value that specifies the length of the data string. For example, if the data string is ten characters in length the actual information passed to the COBOL program would be a two-byte binary value of ten or x'000A' followed by the ten character data string. If the COBOL program is executed from JCL without a parameter the two-byte binary value would be zero or x'0000'.
IDENTIFICATION DIVISION. PROGRAM-ID. JCLCONC1. AUTHOR. SIMOTIME TECHNOLOGIES. ***************************************************************** * Copyright (C) 1987-2019 SimoTime Technologies. * * * * All rights reserved. Unpublished, all rights reserved under * * copyright law and international treaty. Use of a copyright * * notice is precautionary only and does not imply publication * * or disclosure. * * * * Permission to use, copy, modify and distribute this software * * for any non-commercial purpose and without fee is hereby * * granted, provided the SimoTime copyright notice appear on all * * copies of the software. The SimoTime name or Logo may not be * * used in any advertising or publicity pertaining to the use * * of the software without the written permission of SimoTime * * Technologies. * * * * Permission to use, copy, modify and distribute this software * * for any commercial purpose requires a fee to be paid to * * SimoTime Technologies. Once the fee is received by SimoTime * * the latest version of the software will be delivered and a * * license will be granted for use within an enterprise, * * provided the SimoTime copyright notice appear on all copies * * of the software. The SimoTime name or Logo may not be used * * in any advertising or publicity pertaining to the use of the * * software without the written permission of SimoTime * * Technologies. * * * * SimoTime Technologies makes no warranty or representations * * about the suitability of the software for any purpose. It is * * provided "AS IS" without any expressed or implied warranty, * * including the implied warranties of merchantability, fitness * * for a particular purpose and non-infringement. SimoTime * * Technologies shall not be liable for any direct, indirect, * * special or consequential damages resulting from the loss of * * use, data or projects, whether in an action of contract or * * tort, arising out of or in connection with the use or * * performance of this software * * * * SimoTime Technologies * * 15 Carnoustie Drive * * Novato, CA 94949-5849 * * 415.883.6565 * * * * RESTRICTED RIGHTS LEGEND * * Use, duplication, or disclosure by the Government is subject * * to restrictions as set forth in subparagraph (c)(1)(ii) of * * the Rights in Technical Data and Computer Software clause at * * DFARS 52.227-7013 or subparagraphs (c)(1) and (2) of * * Commercial Computer Software - Restricted Rights at 48 * * CFR 52.227-19, as applicable. Contact SimoTime Technologies, * * 15 Carnoustie Drive, Novato, CA 94949-5849. * ***************************************************************** * This program is provided by SimoTime Technologies * * Our e-mail address is: helpdesk@simotime.com * * Also, visit our Web Site at http://www.simotime.com * ***************************************************************** * Source Member: JCLCONC1.CBL ***************************************************************** * * JCLCONC1 - This program will process a JCL parameter. * * CALLING PROTOCOL * ---------------- * USE STANDARD PROCEDURE TO EXECUTE, RUN OR ANIMATE. * * DESCRIPTION * ----------- * This program will process the JCL parameter from the PARM * keyword of the EXEC staement. * * // EXEC PGM=PROGNAME,PARM='text string...' * * This program will simply display the text string. * **************************************************************** * * MAINTENANCE * ----------- * 1997/02/27 Simmons, Created program. * ***************************************************************** * DATA DIVISION. WORKING-STORAGE SECTION. * ***************************************************************** * Data-structure for Title and Copyright... * ------------------------------------------------------------ 01 SIM-TITLE. 05 T1 pic X(11) value '* JCLCONC1 '. 05 T2 pic X(34) value 'Conditional JCL with a Parameter '. 05 T3 pic X(10) value ' v03.01.24'. 05 T4 pic X(24) value ' http://www.simotime.com'. 01 SIM-COPYRIGHT. 05 C1 pic X(11) value '* JCLCONC1 '. 05 C2 pic X(20) value 'Copyright 1987-2019 '. 05 C3 pic X(28) value ' SimoTime Technologies '. 05 C4 pic X(20) value ' All Rights Reserved'. 01 SIM-THANKS-01. 05 C1 pic X(11) value '* JCLCONC1 '. 05 C2 pic X(32) value 'Thank you for using this program'. 05 C3 pic X(32) value ' provided from SimoTime Technolo'. 05 C4 pic X(04) value 'gies'. 01 SIM-THANKS-02. 05 C1 pic X(11) value '* JCLCONC1 '. 05 C2 pic X(32) value 'Please send all inquires or sugg'. 05 C3 pic X(32) value 'estions to the helpdesk@simotime'. 05 C4 pic X(04) value '.com'. 01 FIRST-TIME pic X value 'Y'. 01 MESSAGE-BUFFER. 05 MESSAGE-HEADER pic X(11) value '* JCLCONC1 '. 05 MESSAGE-TEXT pic X(68). 01 MESSAGE-TEXT-01. 05 filler pic X(27) value '***-JCL Parameter length = '. 05 JCL-PARM-LENGTH pic 9(5) value 0. 01 MESSAGE-TEXT-02. 05 filler pic X(8) value '***-JCL '. 05 MESSAGE-TEXT-02-JCL pic X(60) value SPACES. 01 LOCAL-RETURN-CODE pic S9(9) comp value 0. 01 WORK-07 pic X(7) value SPACES. ***************************************************************** LINKAGE SECTION. 01 PARM-BUFFER. 05 PARM-LENGTH pic S9(4) comp. 05 PARM-DATA pic X(256). ***************************************************************** PROCEDURE DIVISION using PARM-BUFFER. if FIRST-TIME not = 'N' perform Z-POST-COPYRIGHT move 'N' to FIRST-TIME end-if subtract LOCAL-RETURN-CODE from LOCAL-RETURN-CODE add PARM-LENGTH to ZERO giving JCL-PARM-LENGTH move MESSAGE-TEXT-01 to MESSAGE-TEXT perform Z-POST-MESSAGE if PARM-LENGTH > 0 move PARM-DATA(1:PARM-LENGTH) to MESSAGE-TEXT-02-JCL move MESSAGE-TEXT-02 to MESSAGE-TEXT perform Z-POST-MESSAGE perform SET-LOCAL-RETURN-CODE end-if perform Z-THANK-YOU. add LOCAL-RETURN-CODE to ZERO giving RETURN-CODE GOBACK. ***************************************************************** SET-LOCAL-RETURN-CODE. subtract LOCAL-RETURN-CODE from LOCAL-RETURN-CODE if PARM-LENGTH > 6 move PARM-DATA(1:7) to WORK-07 evaluate WORK-07 when 'MSG-00 ' move ZERO to LOCAL-RETURN-CODE when 'MSG-04 ' add 4 to ZERO giving LOCAL-RETURN-CODE when 'MSG-08 ' add 8 to ZERO giving LOCAL-RETURN-CODE when 'MSG-12 ' add 12 to ZERO giving LOCAL-RETURN-CODE when 'MSG-16 ' add 16 to ZERO giving LOCAL-RETURN-CODE end-evaluate end-if exit. ***************************************************************** * Display Copyright or Program Messages... ***************************************************************** Z-POST-COPYRIGHT. display SIM-TITLE upon console display SIM-COPYRIGHT upon console exit. ***************************************************************** Z-POST-MESSAGE. display MESSAGE-BUFFER upon console move SPACES to MESSAGE-TEXT exit. ***************************************************************** Z-THANK-YOU. display SIM-THANKS-01 upon console display SIM-THANKS-02 upon console exit. ***************************************************************** * This example is provided by SimoTime Technologies * * Our e-mail address is: helpdesk@simotime.com * * Also, visit our Web Site at http://www.simotime.com * *****************************************************************
The jobs and documentation included in this test case are intended to assist the reader in developing a better understanding of how mainframe JCL can do conditional processing and parameter passing. This document may be used to assist as a tutorial for new programmers or as a quick reference for experienced programmers.
In the world of programming there are many ways to solve a problem. This documentation and software were developed and tested on systems that are configured for a SIMOTIME environment based on the hardware, operating systems, user requirements and security requirements. Therefore, adjustments may be needed to execute the jobs and programs when transferred to a system of a different architecture or configuration.
SIMOTIME Services has experience in moving or sharing data or application processing across a variety of systems. For additional information about SIMOTIME Services or Technologies please contact us using the information in the Contact or Feedback section of this document.
Software Agreement and Disclaimer
Permission to use, copy, modify and distribute this software, documentation or training material for any purpose requires a fee to be paid to SimoTime Technologies. Once the fee is received by SimoTime the latest version of the software, documentation or training material will be delivered and a license will be granted for use within an enterprise, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Technologies.
SimoTime Technologies makes no warranty or representations about the suitability of the software, documentation or learning material for any purpose. It is provided "AS IS" without any expressed or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. SimoTime Technologies shall not be liable for any direct, indirect, special or consequential damages resulting from the loss of use, data or projects, whether in an action of contract or tort, arising out of or in connection with the use or performance of this software, documentation or training material.
This section includes links to documents with additional information that are beyond the scope and purpose of this document. The first group of documents may be available from a local system or via an internet connection, the second group of documents will require an internet connection.
Note: A SimoTime License is required for the items to be made available on a local system or server.
The following links may be to the current server or to the Internet.
Note: The latest versions of the SimoTime Documents and Program Suites are available on the Internet and may be accessed using the icon. If a user has a SimoTime Enterprise License the Documents and Program Suites may be available on a local server and accessed using the icon.
Explore the JCL Connection for more examples of JCL functionality with programming techniques and sample code.
Explore the COBOL Connection for more examples of COBOL programming techniques and sample code.
Explore an Extended List of Software Technologies that are available for review and evaluation. The software technologies (or Z-Packs) provide individual programming examples, documentation and test data files in a single package. The Z-Packs are usually in zip format to reduce the amount of time to download.
Explore The ASCII and EBCDIC Translation Tables. These tables are provided for individuals that need to better understand the bit structures and differences of the encoding formats.
Explore The File Status Return Codes that are used to interpret the results of accessing VSAM data sets and/or QSAM files.
The following links will require an internet connect.
A good place to start is The SimoTime Home Page for access to white papers, program examples and product information. This link requires an Internet Connection
Explore The Micro Focus Web Site for more information about products (including Micro Focus COBOL) and services available from Micro Focus. This link requires an Internet Connection.
Explore the Glossary of Terms for a list of terms and definitions used in this suite of documents and white papers.
This document was created and is maintained by SimoTime Technologies. If you have any questions, suggestions, comments or feedback please use the following contact information.
1. | Send an e-mail to our helpdesk. |
1.1. | helpdesk@simotime.com. |
2. | Our telephone numbers are as follows. |
2.1. | 1 415 763-9430 office-helpdesk |
2.2. | 1 415 827-7045 mobile |
We appreciate hearing from you.
SimoTime Technologies was founded in 1987 and is a privately owned company. We specialize in the creation and deployment of business applications using new or existing technologies and services. We have a team of individuals that understand the broad range of technologies being used in today's environments. Our customers include small businesses using Internet technologies to corporations using very large mainframe systems.
Quite often, to reach larger markets or provide a higher level of service to existing customers it requires the newer Internet technologies to work in a complementary manner with existing corporate mainframe systems. We specialize in preparing applications and the associated data that are currently residing on a single platform to be distributed across a variety of platforms.
Preparing the application programs will require the transfer of source members that will be compiled and deployed on the target platform. The data will need to be transferred between the systems and may need to be converted and validated at various stages within the process. SimoTime has the technology, services and experience to assist in the application and data management tasks involved with doing business in a multi-system environment.
Whether you want to use the Internet to expand into new market segments or as a delivery vehicle for existing business functions simply give us a call or check the web site at http://www.simotime.com
Return-to-Top |
Conditional JCL & Parameter Passing to a COBOL Program |
Copyright © 1987-2025 SimoTime Technologies and Services All Rights Reserved |
When technology complements business |
http://www.simotime.com |