check if dataset exists in jcl
How to check dataset existence using JCL
Some times dataset which is used as input to your job step may or may not exists. In that case job might abend with the JCL error.
In some cases the dataset which job step is going to create is already exists. In this case job will abend with error saying "Duplicate dataset exists".
To handle both the above cases we need to find the way to check whether the dataset exists or not. Based on the existence or non-existence of a dataset we might need to change the behavior of a job.
Example JCL to check for dataset existence using IDCAMS
The following example will explain how you can check whether the dataset exists or not
//TFILECHK JOB (T,XX,XXX),XXXXXXX,CLASS=S, // MSGCLASS=0,REGION=0M //STEP01 EXEC PGM=IDCAMS //SYSPRINT DD SYSOUT=* //SYSIN DD * LISTCAT ENTRIES('YOUR.DATASET.NAME') // IF RC = 0 THEN //* Write your JCL code here. This code will //* execute only if the dataset exists // ENDIF
Good JCL books to refer
In the above code we are asking a question do you have dataset with name
"YOUR.DATASET.NAME". If the dataset exists then IDCAMS returns 0
If the dataset doesn't exists then returns the code which > 0
Based on the return code returned we can control the flow of execution using IF statement or we can also use Condition codes.
Example JCL code to check fro an empty file
Jon run details
IDCAMS shows file or dataset is exists(RC =0)
All steps ran fine
Check you JCL knowledge
What if datat set which i am trying to create is already exists.
First check whether the dataset exists or not by using the above explained code. If the dataset is exists i.e RC=0 then DELETE the dataset by using IEFBR14.
Later after the delete is done we can have a logic which will create the dataset.
1) How to send an email from mainframe -- Example JCL code
There are situation where in you need to send an email from a JCL to your client or to the business
people. Chek out this hub for example JCL code to send an email
2) How to send an email with attachment from mainframe -- Example JCL code
In some cases reports which you generate from JCL needs to be sent to your client through email as an attachment. This hub explains you how you can send email with an attachment to your client or business.
More by this Author
In our previous tutorial we have learned how to send an email from mainframe JCL. This part of the tutorial explains how we can send an email with an attachment from mainframe with JCL code. IBM utility IEBGENER is...
Sort can be used to split the file into multiple files. SORT parameter OUTLIM is used to copy the contents of file into multiple files. The following are the examples to split the file using OUTLIM
No comments yet.