|
|||||
|
This suite of programs provides an example of how mainframe JCL can do conditional processing. The first JCL example will focus on the approaches used by JES/2 using the "COND=" parameter on the JOB or EXEC statement. With JES/3 the conditional processing was improved to use "IF" statements. The second JCL example will focus on the IF, THEN, ELSE and ENDIF statement construct. Both JCL examples accomplished the same task. However, the second JCL example has additional information displayed when there is a difference between the actual and expected return code.
The use of the COND parameter can be very difficult to code and understand. I would recommend the use of the IF, THEN, ELSE and ENDIF statement construct if you have a choice.
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. Two JCL members are provided to run the jobs as an MVS batch jobs on an IBM mainframe or within a project with Micro Focus Mainframe Express (MFE) running on a PC with Windows (refer to http://www.microfocus.com ). This program may serve as a tutorial for programmers that are new to COBOL and mainframe JCL and as a reference for experienced programmers.
The following is the mainframe JCL (JCLCONJ1.JCL) example that uses the COND parameter. 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.
//JCLCONJ1 JOB SIMOTIME,ACCOUNT,CLASS=1,MSGCLASS=0,NOTIFY=CSIP1 //JOBLIB DD DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR //* ******************************************************************* //* This program is provided by: * //* SimoTime Enterprises, LLC * //* (C) Copyright 1987-2008 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 Enterprises //* 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...' //* //COND00B EXEC PGM=JCLCONC1,COND=(0,LT),PARM='Return Code = 00...' //* //* The preceding step (COND00B) will be bypassed if the Return Code //* of any of the preceding job steps is not zero (0). //* //* ******************************************************************* //* 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...' //* //COND04B EXEC PGM=JCLCONC1,COND=(4,NE,COND04A), // PARM='Return Code is equal to 04...' //* //* The preceding step (COND04B) will be bypassed if COND=4 is not //* equal to the Return Code 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...' //* //COND08B EXEC PGM=JCLCONC1,COND=(8,LT,COND08A), // PARM='Return Code is equal to or greater than 08...' //* //* The preceding step (COND08B) will be bypassed if COND=8 is less //* than or equal to the Return Code of the preceding job step //* (COND08A). //* //* ******************************************************************* //* Execute the COBOL program with a parameter. //* //EOJTEST1 EXEC PGM=JCLCONC1,COND=(1,GE), // PARM='All Job Steps had a zero Return Code...' //* //* The preceding step (EOJTEST1) should be bypassed. //* //EOJTEST2 EXEC PGM=JCLCONC1,COND=(8,LT), // PARM='All Job Steps had a Return Code of 0 through 8...' //* //* The preceding step (EOJTEST2) should execute. //* //EOJTEST3 EXEC PGM=JCLCONC1,COND=(9,GE), // PARM='Return Code greater than 8 for a job step.' //* //* The preceding step (EOJTEST3) should be bypassed. //*
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 zer (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 program is provided by: * //* SimoTime Enterprises, LLC * //* (C) Copyright 1987-2008 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 Enterprises //* 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 ENTERPRISES.
*****************************************************************
* Copyright (C) 1987-2008 SimoTime Enterprises, LLC. *
* *
* All rights reserved. Unpublished, all rights reserved under *
* copyright law and international treaty. Use of a copyright *
* notice is precautionary only does not imply publication or *
* disclosure. This software contains confidential information *
* and trade secrets of SimoTime Enterprises, LLC. No part of *
* this program or publication may be reproduced, transmitted, *
* transcribed, stored in a retrieval system, or translated into *
* any language or computer language, in any form or by any *
* means, electronic, mechanical, magnetic, optical, chemical, *
* manual or otherwise, without the prior written permission of: *
* *
* SimoTime Enterprises *
* 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 Enterprises, *
* 15 Carnoustie Drive, Novato, CA 94949-5849. *
* *
*****************************************************************
* This program is provided by SimoTime Enterprises *
* 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 ' v1.1.00 '.
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-2008 '.
05 C3 pic X(28) value ' SimoTime Enterprises, LLC '.
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 sample '.
05 C3 pic X(32) value 'by SimoTime Enterprises, LLC '.
05 C4 pic X(04) value ' '.
01 SIM-THANKS-02.
05 C1 pic X(11) value '* JCLCONC1 '.
05 C2 pic X(32) value 'Please send comments or suggesti'.
05 C3 pic X(32) value 'ons to helpdesk@simotime.com '.
05 C4 pic X(04) value ' '.
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-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.
The purpose of this document is to assist as a tutorial for new programmers or as a quick reference for experienced programmers. These sample programs are made available on an "as-is" basis and may be downloaded, copied and modified for specific situations as long as the copyright information is not removed or changed. As always, it is the programmer's responsibility to thoroughly test all programs.
Permission to use, copy, modify and distribute this software for any commercial purpose requires a fee to be paid to SimoTime Enterprises. 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 Enterprises.
Permission to use, copy, modify and distribute this software for a 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 Enterprises.
SimoTime Enterprises makes no warranty or representations about the suitability of the software for any purpose. It is provided "AS IS" without any express or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. SimoTime Enterprises 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.
If you have any questions, suggestions or comments please call or send an e-mail to: helpdesk@simotime.com
You may download this example at http://www.simotime.com/sim4dzip.htm#JCLConditionalZip as a Z-Pack. The 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.
Please view the complete list of SimoTime Z-Pack Examples at http://www.simotime.com/sim4dzip.htm .
Note: You must be attached to the Internet to download a Z-Pack or view the list.
Check out The JCL Connection for more mainframe JCL examples.
Check out The COBOL Connection for more examples of mainframe COBOL coding techniques and sample code. Also, take a look at a simple example of parameter passing between JCL and COBOL.
The Pass, Parse and Convert Data Strings has examples of using COBOL for passing a parameter from JCL to COBOL plus other translation and parsing routines.
Check out The SimoTime Glossary for a list of terms and definitions used in the documents provided by SimoTime.
If you have any questions, suggestions or comments please call or send an e-mail to: helpdesk@simotime.com
We appreciate your comments and feedback.
Founded in 1987, SimoTime Enterprises is a privately owned, Limited Liability Corporation located in Novato, California. 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. This includes the smallest thin client using the Internet and the very large mainframe systems. There is more to making the Internet work for your company's business than just having a nice looking WEB site. It is about combining the latest technologies and existing technologies with practical business experience. It's about the business of doing business and looking good in the process. 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. 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 |
| Copyright © 1987-2008 SimoTime Enterprises, LLC All Rights Reserved |
| When technology complements business |
| http://www.simotime.com |