-2

One Jcl question

We have 3 steps in jcl, Step1 Step2 Step3 If step 1 output empty ,then step2 need to run else step 3 need to be run. Any one know answer? It should not be add any new steps and solution should be thru jcl only

Anji
  • 1
  • 1
    How do you define empty output? Some file is empty? – uncaught_exception Mar 26 '17 at 03:17
  • 2
    Nope, no way, unless "step 1 output empty" means the step return-code has a specific value which it does not have for not ( "step 1 output empty" ). JCL can test return-codes, and nothing else. Sounds like the interviewer (or the rubbishy website you are taking this from) doesn't have a clue about JCL, or does have a clue about JCL but is incapable of phrasing a question accurately. – Bill Woodger Mar 26 '17 at 14:36
  • The program that creates the file should know if it is empty. Have that program set a return code of 0 if the file contains anything. Otherwise, set a return code of 1 and then bypass whatever steps you need to. – SaggingRufus Mar 27 '17 at 11:41

2 Answers2

2

if you would like to do that with JCL there are several possibilities. I give you my favorite one:

//* Using IDCAMS                                                   
//* -------------------------------------------------------------------
//* Sets RC=0000 if dataset has records.                              *
//* Sets RC=0004 if dataset is empty.                                 *
//*-------------------------------------------------------------------*
//IDCAMS0  EXEC PGM=IDCAMS                                             
//SYSPRINT DD SYSOUT=*                                                 
//MYFILE   DD DISP=SHR,DSN=<Dataset Name>       
//SYSIN    DD *                                                        
 PRINT INFILE(MYFILE) CHARACTER COUNT(1) 

Regards, Andreas

0

I wouldn't call it an elegant solution, but one simple way to handle this is to write yourself a short program that runs after step 1 and before step 2. This program checks to see if the output file from step 1 is empty or not, setting the return code to indicate one from the other, and then you can use standard JCL COND checking on the subsequent steps to get the result you want.

There are lots of ways to check for empty files...I'd use stat() in C/C++, but it can be done in Java and even REXX or other scripting languages if you prefer. In worst case, you just open and read the input file, returning the empty return code if you get an immediate EOF, otherwise return the non-empty return code.

Valerie R
  • 1,769
  • 9
  • 29