How to test the given dataset is empty (or) not through jcl in mainframes?

Showing Answers 1 - 50 of 50 Answers

vamshi

  • Jun 20th, 2006
 

//**********************************************************************
//*                                                                     *
//*  CHECK IF FILE IS EMPTY                                                         *
//*                                                                                           *
//**********************************************************************
//SCHKEMP EXEC PGM=IDCAMS,                                              
//             COND=(4,LT)                                              
//SYSIN    DD  *                                                        
     REPRO IFILE(IT01) OFILE(OT11) COUNT(1)                             
//IT01     DD  DSN=dsnname,          
//             DISP=OLD                                                 
//OT11     DD  DUMMY,                                                   
//             DCB=(RECFM=VB,LRECL=2034)                                 
//   IF SCHKEMP.RC = 4 THEN

//FILE1    DD  *                             
   THE FILE IS EMPTY
/*   

//SYSPRINT DD  SYSOUT=*                                                  
//SYSABEND DD  SYSOUT=X,                     
//             HOLD=YES                      
//*                                                                                                 

  Was this answer useful?  Yes

RUPA . S

  • Aug 16th, 2006
 

try to open the dataset in cobol in input mode u cant ioen the file if it is empty u will get a non zero file status

  Was this answer useful?  Yes

krushnat

  • Nov 12th, 2006
 

Hi

  i want to know to check the newly added record in dataset in vb.net

  Was this answer useful?  Yes

Sridhar

  • Nov 24th, 2006
 

Use simple Sort utility JCL and try to copy the data (SORT FIELDS = COPY) form the file which you want to test to an output file. in Sysout of the job run you can see the record counts of input and output files. This gives the count of the data which you want to test.

  Was this answer useful?  Yes

Smitha Brindavan

  • Mar 15th, 2007
 

Return codes can be set to 12 if the dataset is empty and 0 if not empty, using ICETOOL. Subsequent processing can follow based on the return code in the ICETOOL step, as required.

In this below example, Return code of STEP1 will be set to 12 if dataset USERNAME.FILE1 is empty. STEP2 will run if return code is 0, i.e if dataset is not empty.

//STEP1   EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//INFILE DD DSN=USERNAME.FILE1,DISP=SHR
//TOOLIN DD *
 COUNT FROM(INFILE) EMPTY
/* 
//IF STEP1.RC=0 THEN         
//STEP2 EXEC PGM = *****
...
//ENDIF

  Was this answer useful?  Yes

//********************************************************************
//*    CHECK FOR EMPTY Dataset        .                              *
//********************************************************************
//*
//CHKEMP   EXEC PGM=IDCAMS,TIME=800,REGION=150K
//*
//INPUT1   DD DSN=DSNNAME,DISP=SHR
//OUTPUT1  DD DUMMY,
//            DCB=(RECFM=FB,LRECL=700,BLKSIZE=0)
//*
//SYSIN    DD *
  REPRO -
       INFILE (INPUT1) -
       OUTFILE (OUTPUT1) -
       SKIP(01)
/*
//SYSOUT   DD SYSOUT=*                                             
//SYSPRINT DD SYSOUT=*                                         
//SYSUDUMP DD SYSOUT=*                                          
//CEEDUMP  DD SYSOUT=*                                          
//SYSOUD   DD SYSOUT=*                                        
//*
//******************************************************************
//* CHECKS FOR RETURN CODE CHECKEMP
//******************************************************************
// IF (CHKEMP.RC EQ 12) THEN
//FILE1    DD  *                             
   THE FILE IS NOT EMPTY
/*
//******************************************************************
// IF (CHKEMP.RC NE 12) THEN
//FILE1    DD  *                             
   THE FILE IS EMPTY
/*

  Was this answer useful?  Yes

therealdeal

  • Feb 17th, 2008
 

You can check whether a dataset has any values of empty without writing a jcl too..Just go to the job where it is present... Type "tso cb" in the command and keep in the mouse arrow on the dataset and press enter you can see the contents of the dataset...

  Was this answer useful?  Yes

jvsamycts

  • Oct 10th, 2009
 

Simply you can use the below sort card,

SORT FIELDS=COPY            
OUTFIL FILES=1,NULLOFL=RC4  

SORTIN    - Dataset to be tested for Empty
SORTOF1  - Output file..... it can be temp file...

While executing this Sort step, it will return RC 4 when the input file is empty.

  Was this answer useful?  Yes

sunil

  • Jan 24th, 2012
 

what u said is exactly correct vamshi. we can check using outfile dummy and count(1) whether the file is empty or not.

  Was this answer useful?  Yes

Uday Suthapalli

  • Jul 4th, 2012
 

We can do it using sort aswell..

//EMPTYCHK EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=INPUT.FILE,DISP=SHR
//SORTOUT DD DSN=&&TEMP1,DISP=(NEW,PASS),
// UNIT=SYSDA,SPACE=(give space parms),
// DCB=(RECFM=FB,LRECL=reclenght,DSORG=discorg)
//SYSIN DD *
SORT FIELDS=COPY
//CHECKFIL IF EMPTYCHK.RC = 12 THEN
File is empty
//CHECKFIL ENDIF

  Was this answer useful?  Yes

Srinivas reddy Polepalli

  • Jul 23rd, 2012
 

Here we can verify the empty data set using the utility IDCAMS.
For example:

Code
  1. //SYSIN DD *

  2.     PRINT INDATASET(INPUT DATA SET NAME) -

  3.     CHARACTER COUNT(1).

  4.  



Here if the return code of this step is 0 this means dataset is not empty.

If the return code = 4 then it means its an empty dataset.
This also one way of empty dataset verification....

KTreddy

  • Jan 5th, 2017
 

Code
  1. you can use below code

  2. //s1    EXEC DATCHKP,

  3. //             INPUT=here data set you want to check ,PARM=02

  4. //s2  IF (s1.CHCK10.RC EQ 00 ) THEN

  5. //*if dataset has data it will go inside loop and execute the steps ,if its empty it will go to ENDIF

  6. // step you want to perfrom

  7. //stepname ENDIF

  Was this answer useful?  Yes

Sireesha Akula

  • Jan 12th, 2017
 

Use below code in JCL. If the file is empty, the step fails with return code 04.
//JS010 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//IN1 DD DISP=SHR,DSN=Input file name
//SYSIN DD *
PRINT INFILE(IN1) COUNT(1)

  Was this answer useful?  Yes

Mayank

  • Apr 6th, 2017
 

PRINT IDS(FILE NAME) CHAR COUNT(1)

  Was this answer useful?  Yes

Mayuresh

  • May 9th, 2017
 

Using IDCAMS

  Was this answer useful?  Yes

vidhya

  • Oct 1st, 2017
 

IDCAMS

  Was this answer useful?  Yes

KRISHNAMOHAN

  • Jul 12th, 2019
 

HERE IF THE INPUT FILE DSNNAME IS DYNAMIC. Means I need to perform this step for 30 files . How??

  Was this answer useful?  Yes

Mehul Patel

  • Dec 23rd, 2022
 

It does not work with SORT/SYNCSORT. It completes with RC=0 even if the input file is empty. Try to test it and surprise yourself. Happy learning!

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions