Sunday, 8 August 2021

JCL


JCL stands for Job Control Language. JCL is a means of communication between operating system and source program. (source programms can be written in COBOL, Assembler or PLI).




 Structure of JCL :

JCL consists of below fields –
1) Identification  Field – It starts from column 1 and length is 2 bytes. Two forward slashes (//) starting form 1st column is name field.

2) Name field – Name field starts from column 3 and will be of 1 to 8 alphanumeric characters.

3)Operational field : It starts from column 12.

4)Parameters field : it starts after end of operational field followed by one or more than one space.



---
There are two types of parameters –
1)      Positional Parameters : These parameters have fixed position, Position cann’t be shifted.
a)      Accounting information
b)      Programmers name
c)       PGM
d)      PROC

Note : PGM & PROC are two execptional positional fields which have equal sign.


2)      Keyword Parameters   : These parameters have equal sign with some values, position of these fields can be shifted.
a)   CLASS
b)   MSGCLASS
c)    MSGLEVEL
d)    NOTIFY
e)    USER
f)     OWNER
g)    TIME
h)    REGION
i)    COND
j)    RESTART
k) PRTY
l) PARM
         
Some parameters can be coded on JOB statement and some can be  or EXEC statement like TIME, REGION, COND & PARM.

Accounting Information :
Accounting information is realted to billing, dollar cost of job will be decided on this parameter. Maximum size 142 charecters.

//OZA201AS JOB (GENERAL),
Note :If position of Acccounting information is changed then job will give syntax error.


Programmers name :
Programmer name filed tells the name of programmer. Maximum length is 20 charecters.

//OZA201AS JOB (GENERAL), 'SANDIP WALSINGE',
Note :If position of programmer's name is changed then job will give syntax error.


PGM  :
PGM is positional parameter which is coded on exec statement. It tells the system which program (Load module or Utility ) needs to be executed.

//STEP010  EXEC PGM=TESTPROG


PROC :
PROC is positional parameter which is coded on exec statement. It tell system which procedure needs to be executed.

//STEP010  EXEC PROC=CATPROC

//STEP010  EXEC CATPROC - It has same meaning as previous statement.


CLASS :
Class parameters tell system about nature of job, if job is simple I/O type then lower class can be allocated to the job, if job is complex calculation related then higher class can be allocated to the job.
Values : A to Z or 0(Zero) to 9.

//OZA201AS JOB (GENERAL),'SANDIP',CLASS=A


MSGCLASS :
MSGCLASS parameter tells system where output messages should or job should be routed/transfered after execution.
Values : A to Z or 0(zero) to 9.

//OZA201AS JOB (GENERAL),'SANDIP',MSGCLASS=J
This will route job & messages to JHS (JHS is CA tool ). If nothing is coded then job will go to spool area.


MSGLEVEL :
MSGLEVEL parameter tells system how JCL, allocation messages and termination messages are printed in job listing after execution of job.
MSGLEVEL=(x,y)

X can have below values -
x=0,1,2
0 - Only JOB statement will printed after execution JESJCL step.
1 - JOB, JCL and expanded procedures will be printed JESJCL step.
2 - JOB & JCL statements will be printed in JESJCL step.

y Can have below values -
y=0,1
0 - JCL messages & allocation will be printed if job terminates abnormally.
1 - JCL messages & allocation will be printed if job terminates normally or abnormally.

NOTIFY :
NOTIFY Parameter gives notification to the user on successful or unsuccessful completion of job. 

NOTIFY=USERID OR (It will notification to the user whose userid is provided here as a user id)
NOTIFY=&SYSUID (It will notification to user who is executing the job.)  

//OZA201AS  JOB (GENERAL),'SANDIP WALSINGE',NOTIFY=OZA201




USER :
This parameter is rarely used parameter. This is to identify user.
//OZA201AS  JOB (GENERAL),'SANDIP WALSINGE',USER=OZA201


OWNER :
Owner is same as USER parameter, it will tell about owner of the job.
//OZA201AS  JOB (GENERAL),'SANDIP WALSINGE',OWNER=OZA201


TIME :
TIME parameter allocates maximum CPU time to the job or step. If job/step takes more time to execute than time provided in TIME parameter then job will abend with S322 abend code.

Job parameter can be coded on both JOB and EXEC statement.

*TIME parameter coded on EXEC will override TIME parameter coded on JOB statement.

Syntax :
TIME=(min,sec) or
TIME=(,)              - It will give system defined time.
TIME=1440          - It will give unlimited time.
TIME=NOLIMIT  - It will give unlimited time.
TIME=MAXIMUM - Job will run maximum 248.55 days.

//OZA201AS  JOB (GENERAL),'SANDIP WALSINGE',TIME=(min,sec)

//STEP1 EXEC  PGM=TESTPROG,TIME=(2,20)


REGION :
REGION parameter allocates storage space for execution of the job. It can be coded on both JOB & EXEC statement. It can be coded either in Kilobytes (K) or Megabytes (M). When coded in Kilobytes or Megabytes it should be in multiple of 4. Maximum 2GB storage space can be allocated in REGION Parameter. 

*REGION coded on JOB statement will override REGION on EXEC statement.

//OZA201 JOB (GENERAL),'SANDIP WALSINGE',REGION=0M

//STEP1 EXEC PGM=TESTPROG,REGION=0M

If REGION specified in JOB is not sufficient then job abends with S422 or S822 abend code. 

COND :
COND parameter is coded to control execution of steps from job.

Ex : In 1st step account holder's transaction data is getting copied from transaction file to some output file for bkup purpose, in 2nd step transction file is getting deleted. 

If step1 fails due to some reason without copying data, but in step2 trandaction file will be deleted, so we will miss important data without taking bkup, in order to avoid such scenarios COND parameters are used.

*COND paramter can be coded on both JOB & EXEC statement.


Syntax :

COND=(comparison code, condition code)
EX: COND=(0,EQ)
Comparison code can have values like 0,4,8,12,16.
Condition code can be GT,LT,EQ,GE,LE.

COND=(comparison code, condition code, stepname)
EX: COND=(0,EQ,STEP1)

COND=(comparision code, condition code, PROCNAME.STEPNAME)
EX: COND=(0,EQ,TESTPROC.STEP1)

*IF Condition is TRUE then step will be skipped.
*IF condition is FALSE then step will be executed.

COND=EVEN - Step on which this condition is coded will execute when previous step terminates normally or abnormally.

COND=ONLY - Step on which this condition is coded will execute when previous step terminates only abnormally.


*COND coded on JOB statement will override COND on EXEC statement.

System first checks COND parameter from JOB statement, if it is true, then it will not check COND parameter from EXEC step(It will ignore COND parameter of EXEC step). If COND parameter from JOB step is false then it will check COND parameter from EXEC step. 


//OZA201AS JOB (GENERAL),'COND TEST',
//         CLASS=8,                  
//         PRTY=15,                  
//         TIME=(5),                 
//         MSGCLASS=Q,               
//         MSGLEVEL=(1,1),           
//         REGION=0M,                
//         COND=(0,NE),              
//         NOTIFY=&SYSUID            
//*                                  
//STEP1         EXEC  PGM=SORT            
//SYSPRINT DD    SYSOUT=*            
//SYSOUT   DD    SYSOUT=*            
//SORTIN    DD    *                   
STEP1   OUTPUT                       
//SORTOUT  DD    SYSOUT=*            
//SYSIN    DD    *                   
    SORT FIELDS=COPY                 
/*                  
//STEP2     EXEC PGM=SORT,COND=(0,EQ)
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTIN DD *
STEP2   OUTPUT
//SORTOUT DD SYSOUT=*
//SYSIN DD *
     SORT FIELDS=COPY
/*                                    

//STEP3   EXEC PGM=SORT
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTIN DD *
STEP3  OUTPUT
//SORTOUT DD SYSOUT=*
//SYSIN DD *
     SORT FIELDS=COPY
/*                                    



Output : 
1) STEP1 will execute with MAXCC=0,
2) For STEP2 execution it will check JOB condition 0 NE 0, condition does not satisfy, so it will check EXEC condition 0 EQ 0, here condition satisfies so it will not execute STEP2.
3) For STEP3 execution again it will check JOB cond 0 NE 0 (STEP1 return code), condition not satisfied, so it will execute STEP3.

 EX 2:

//OZA201AS JOB (GENERAL),'COND TEST',
// CLASS=8,
// PRTY=15,
// TIME=(5),
// MSGCLASS=Q,
// MSGLEVEL=(1,1),
// REGION=0M,
// COND=(0,EQ),
// NOTIFY=&SYSUID
//*
//STEP1 EXEC PGM=SORT
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTIN DD *
STEP1 OUTPUT
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
/*
//STEP2 EXEC PGM=SORT,COND=(0,NE)
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTIN DD *
STEP2 OUTPUT
//SORTOUT DD SYSOUT=*
//SYSIN DD *
     SORT FIELDS=COPY
/*

//STEP3 EXEC PGM=SORT
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTIN DD *
STEP3 OUTPUT
//SORTOUT DD SYSOUT=*
//SYSIN DD *
     SORT FIELDS=COPY
/*



Output :
1) STEP1 will execute with MAXCC=0.

2) For STEP2 execution it will check JOB cond 0 EQ 0, here condition satifies so it will not execute STEP2 though EXEC cond is false ( 0 NE 0), it ignores EXEC cond as JOB cond is satisfied.

3) STEP3 will not execute as JOB cond (0 EQ 0) is true.                                   


RESTART :
Restart parameter is used to restart the job from perticular step.

Syntax : RESTART=stepname or procname.stepname

ex:
//JOB1      JOB (GENERAL),'SANDIP',RESTART=STEP2
//STEP1   EXEC PGM=PROG1
//STEP2   EXEC PGM=PROG2
//STEP3   EXEC PGM=PROG3

Here job will be restarted from step2.



PRTY :
//OZA201AS  JOB (GENERAL),'SANDIP',PRTY=15

It decides priority of the job, higher the priority job will execute sooner, if priority is same for jobs then job will execute on first come first serve basis.

Value ranges from 0 to 15, (14 & 15 are higher Priority). It is coded on JOB statement.



PARM :
//STEP010 EXEC PGM=TESTPRG,PARM='WELCOME TO COBOL'

It is used to pass value from JCL to application program, it is coded on EXEC statement. Maximum 100 characters can be passed thru this parameter. 

Receive PARM value in COB program :
LINKAGE SECTION.
01 PARM-VAR.
       05 PARM-LN             PIC S9(04) COMP.
       05 PARM-TX             PIC X(25).
PROCEDURE DIVISION USING PARM-VAR.
        DISPLAY PARM-TX.
        STOP RUN.  


DD statement Parameters :
1) DISP
2) UNIT
3) DCB
4) SPACE
5) VOLUME
6) DATACLASS


DISP=(x,y,z)

x- Indicates status of job
x can have values NEW, SHR, OLD or MOD.
y - Can have values CATLG, DELETE,UNCATLG,KEEP,PASS
z - Can have values CATLG, DELETE,UNCATLG,KEEP.

NEW  - It indicates dataset is new.

SHR   - It's used for already existing dataset, generally coded for input 
datasets, so that other jobs can share the dataset simultaneously.

OLD   - 
It's used for already existing dataset, generally coded for output datasets so that other jobs can not use this datasets. If records are already present in output file and tried to copy the data in the same file then existing data will be overriden.
  
MOD - It's used for already existing dataset, generally coded for output datasets so that other jobs can not use this datasets. If records are already present in output file and tried to copy the data in the same file then existing data will be apended.

UNIT=SYADA or TAPE
UNIT parameters tells the system where dataset is residing or where datasets needs to created.


DCB :
DCB parameter gives information of dataset related record length, record format, blocksize, dataset organization.

DCB=(LRECL=80,RECFM=FB,BLKSIZE=800,DSORG=PS)

LRECL -  
It tells information about length of record. 80 bytes is standard record length. Generally all source libs copylibs will have record length as 80 and RECFM as FB.

RECFM - 
It tells information about record format of dataset. 

RECFM Can be FB,VB,U,FBA,VBA.
FB - Fixed blocked (Records will have same length). 
VB - Variable blocked ( Records will be of variable length) 
         4 bytes will be reserved for storing information about record length. 
U - Undefined. This RECFM is used for loadlibs. 
FBA - Fixed blocked attirbute. This RECFM is used for report gengeration purpose.
VBA - Variable blocked attribute.

BLKSIZE - 
BLKSIZE parameter gives information about how many records can be stored in one block.

if BLKSIZE=800 and LRECL=80 then one block will contain 10 records. 
When BLKSIZE=0 is provided it means that system will allocated best BLKSIZE on it's own.

DSORG - 
DSORG=PS - Sequential dataset (PS)
DSORG=PO - Partitioned dataset (PDS)

SPACE : 
SPACE=(a,(x,y,z),RLSE,CONTIG,ROUND) 

a - Can have values TRK,CYL,BYTE
x - Priamry quantity space allocation ( in numbers like 1 2 3 )   
y - Seconday quantity space allocation ( in numbers like 1 2 3 )
z - space for directory block (Required for PDS file only not applicable in case of PS files.

SPACE Calculation :
SAPCE=(CYL,(2,3)) - PS
2 * 1 + 3 * 15 = 2 + 45 = 47 Cyclinders will be acllocated.

SPACE=(CYL,(2,3,4)) - PDS
2 * 1 + 3 * 15 = 47 cylinders will be allocated and
4 * 5 = 20  maximum members can be allocated in one dataset.

Parameters RLSE, CONTIG and ROUND are optional. 

RLSE : It releases unused storage spaces of the dataset. It releases unused space of primary quantity only not of secondary.

ex: SPACE=(TRK,(2000,3000),RLSE) 
Let's say data from this dataset requires only 10 TRACKS then primary quantity 1890 tracks will be released, This dataset will have 10 + 3000 = 3010 TRACKS after execution of the job. 

CONTIG: It tells system to allocate storage space contiguously. Again it is applicable for Primary quantity only. If Contiguous space is not available for primary quantity then job will abend. 

ROUND:  It allocates entire cylinder for the dataset.  


SYSTEM NAMES IN JCL:

//STEP1 EXEC PGM=SORT
//SYSPRINT DD SYSOUT=*
//SYSOUT    DD SYSOUT=*
//SYMNAMES DD *
MDT,S'&LYR2.&LMON.&LDAY'
SDT,S'&LYR4.&LMON.&LDAY'
TIM,S'&LHR.&LMIN.&LSEC'
//SORTIN  DD *
TEST1 DATA
//SORTOUT DD DSN=OZA234A.TEST.OUT1,DISP=OLD
//SYSIN  DD *
      SORT FIELDS=COPY
      OUTREC FIELDS=(01:C'SANDIP TEST',01X,MDT,
                                          01X,SDT,01X,TIM,36:01,10,34X)                          
//*

OUPUT OF JOB:
SANDIP TEST 210502 20210502 091704 TEST1 DATA

You can find different SYSTEM NAMES by typing SYM in spool area, it will give list of all system names.



Symbolic and overriding parameters in JCL :

SYMBOLIC PARAMETER: 

CATPROC Cataloged Procedure
OZA7489.SOURCE.PROCLIB - PROCLIB NAME
//CATPROC PROC QUAL1=OZA7489,       <== Symbolic parameter 
//             QUAL2=TEST,                      <== Symbolic parameter  
//             PGM1=SORT                        <== Symbolic parameter    
//* 
//DATA      EXEC PGM=&PGM1 
//SYSPRINT DD SYSOUT=*
//SYSOUT   DD SYSOUT=*
//SORTIN   DD DSN=&QUAL..&QUAL2..INFB,DISP=SHR
//SORTOUT DD DSN=&QUAL1..&QUAL2...IN2,DISP=OLD
//SYSIN      DD *
   SORT FIELDS=COPY
//*


JOB TO EXECUTE ABOVE PROC
//OZA7489S (BUA0,S,T),'CALLPROC',CLASS=B,MSGCLASS=O,
//               NOTIFY=&SYSUID
//LIB JCLLIB ORDER=OZA7489.SOURCE.PROCLIB
//*
//STEP1  EXEC CATPROC
//*


OVERRIDING PARAMETER: 

//OZA7489S (BUA0,S,T),'CALLPROC',CLASS=B,MSGCLASS=O,
//               NOTIFY=&SYSUID
//LIB JCLLIB ORDER=OZA7489.SOURCE.PROCLIB
//*
//STEP1  EXEC CATPROC
//DATA.SORTIN DD DSN=OZA7489.TEST.IN1,  <= OVERRIDING PARAMTER
//                         DISP=OLD
//*

--
Compulsary Statements :
1) JOB statement     - Job statement will tell information about job.
2) EXEC statement  - Exec statement will tell what needs to be executed.
3) DD statement       - DD statement will provide information about input and output files from job.

Other statements :
1) JCLLIB - It provides path of Cataloged procedure. 
2) STEPLIB - It provides path of LOAD libraries.STEPLIB is for perticular step.
3) JOBLIB - It provides path LOAD libraries. JOBLIB is for entire job.


//JOB1      JOB
//JOBLIB   DD DSN=OZA201.JOB.LOADLIB,DISP=SHR
//STEP1  EXEC PGM=PROG1
//STEPLIB DD DSN=OZA201.STEP.LOADLIB,DISP=SHR

In this JOB both JOBLIB and STEPLIB are coded. while executing STEP1 system will search for PROG1 load module in STEPLIB library, if it is not present in STEPLIB library then it will search in JOBLIB library.
If it is found in JOBLIB then STEP1 will be executed by using load module form JOBLIB library. 
         If LOAD module is not present in JOBLIB library then job will abned with S806 abend code. 


Special DD names :

1) SYSIN            - If we want to provide input to JCL then we can provide it in SYSIN statement.
2) SYSABEND   - It will give abend messages after abnormal termination
3) SYSUDUMP   - It will give abend messages after abnormal termination
4) SYSPRINT     - It will print jcl/allocation messages.
5) SYSOUT        - It will route jcl/allocation messages to spool area.


--


IBM Utilities are system defined utilities which will be invoked and executed when provided on step statement by PGM=Utility. Utilities are nothing but the load modules(Executable source in machin language which only machine will understand) which are defined by IBM (or system defined) there no need to provide path of load libraries for these Utilities.

Commonly used Utilities are as below -
1) IEFBR14     - To create, delete catlg or uncatlg datasets(PS or PDS).
2) IEBGENER - To copy data from PS file to PS file.
3) IEBCOPY   - To copy data from PDS file to PDS file.
4) IDCAMS    - Mainly IDCAMS utility is used to do operations like create & delete for VSAM or GDGs and copy for VSAM, GDGs or PS files. 
5) SORT         - There are many operations that can be performed thru SORT utility like - to sort file, to format output file or to copy records.
There are two types of SORT -   
1) DFSORT        - DFSORT is IBM product.
2) SYNCSORT  - SYNCSORT is SYNCSORT product.

From sysout messages we can identify which sort is getting invokded.

Like -
END SYNCSORT -  OZA201AS ( for SYNCSORT ) 
END OF DFSORT - OZA201AS ( for DFSORT)


IEFBR14 :
 Create PS file 

//OZA201AS JOB (GENERAL),'IEFBR14',CLASS=A,NOTIFY=OZA201
//*
//STEP1  EXEC  PGM=IEFBR14
//SYSPRINT DD  SYSOUT=*
//SYSOUT   DD   SYSOUT=*
//DD1        DD   DSN=OZA201.TEST.OUT,
//                     DISP=(NEW,CATLG,DELETE),
//                     SPACE=(TRK,(2,4)),UNIT=SYSDA,
//                     DCB=(LRECL=80,RECFM=FB,BLKSIZE=800,DSORG=PS)
//*


Output : This step will create PS file - OZA201.TEST.OUT.

IEBGENER :
IEBGENER utility is used to copy data from PS file to PS file.

//OZA201AS JOB (GENERAL),'IEBGENER',CLASS=A,NOTIFY=OZA201
//*
//STEP1  EXEC  PGM=IEBGENER
//SYSPRINT DD  SYSOUT=*
//SYSOUT   DD   SYSOUT=*
//SYSUT1   DD   DSN=OZA201.TEST.IN,DISP=SHR
//SYSUT2   DD   DSN=OZA201.TEST.OUT,
//                    DISP=(NEW,CATLG,DELETE),
//                    SPACE=(TRK,(2,4)),UNIT=SYSDA,
//                    DCB=(LRECL=80,RECFM=FB,BLKSIZE=800,DSORG=PS)
//SYSIN      DD  DUMMY
/*

Output : This JCL will copy data from input file to output file.        

   
IEBCOPY :
IEBCOPY is used to copy data from PDS file to PDS file.

//OZA201AS JOB (GENERAL),'IEBCOPY',CLASS=A,NOTIFY=OZA201
//*
//STEP1   EXEC  PGM=IEBCOPY
//SYSPRINT  DD  SYSOUT=*
//SYSOUT      DD  SYSOUT=*
//IN01            DD  DSN=OZA201.TEST.IN.PDS,DISP=SHR
//OUT01        DD  DSN=OZA201.TEST.OUT.PDS,DISP=OLD
//SYSIN         DD  *
         COPY INDD=IN01,OUTDD=OUT01
/*
//

Output : If 3 members are present in input PDS file then it will copy all 3 members in outpput file.


         COPY INDD=IN01,OUTDD=OUT01
         SELECT MEMBER=(MEM1,MEM2)

Output : This will copy MEM1 & MEM2 members in output file.

         COPY INDD=IN01,OUTDD=OUT01
         EXCLUDE MEMBER=MEM1

Output : This will copy all members except MEM1.


 
IDCAMS :
IDCAMS is used to perform create, delete and copy operations on VSAM files. PS files also can be copied by using IDCAMS. GDG base is created with IDCAMS utility.



1) Below JCL will perform below listed operations.
Copy data from PS file to PS
Copy data from VSAM file to VSAM
Copy data from VSAM file to PS
Copy data from PS file to VSAM file.

//OZA201AS JOB (GENERAL),'IDCAMS',CLASS=A,  
//         NOTIFY=OZA201                    
//*                                         
//STEP010  EXEC PGM=IDCAMS                  
//SYSOUT   DD  SYSOUT=*                     
//SYSPRINT DD  SYSOUT=*                     
//DD1      DD  DSN=OZA201.TEST.IN1,         
//             DISP=SHR                     
//DD2      DD  DSN=OZA201.TEST.OUT,DISP=OLD 
//SYSIN    DD  *                            
    REPRO INFILE(DD1) OUTFILE(DD2)          
                                            
/*                                          
//*                                       
  


2) To check whether file is empty or not. If file is empty job will give MAXX=04 and file is contains data it will give MAXCC=00 and will display first record in SYSPRINT.


//OZA201AS JOB (GENERAL),'IDCAMS',CLASS=A,
//         NOTIFY=OZA201                  
//*                                       
//STEP010  EXEC PGM=IDCAMS                
//SYSOUT   DD  SYSOUT=*                   
//SYSPRINT DD  SYSOUT=*                   
//DD1      DD  DSN=OZA201.TEST.IN,DISP=SHR
//SYSIN    DD  *                          
    PRINT INFILE(DD1) CHAR COUNT(1)                                        
/*                                        
//*                                       


NOTE : VSAM fiie operations and GDG creation will be covered later in respective topics.


SORT :
SORT can be used for many opertations like COPY output record formation, remove duplicates, copy selected rows or columns, comapre two files.

1) Sort file on the basis of emp-code

Input file Layout :
21400       sandip
21200       mandip     
21100       randip

emp-code starts from 1st column and length is 5 chars, emp-name starts from 7th column and lenght is 6 chars.


//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A, 
//         NOTIFY=OZA201                   
//*                                        
//STEP010  EXEC PGM=SORT                   
//SYSOUT   DD  SYSOUT=*                    
//SYSPRINT DD  SYSOUT=*                    
//SORTIN   DD  DSN=OZA201.SORT.IN,DISP=SHR       
//SORTOUT  DD  DSN=OZA201.SORT.OUT,DISP=OLD
//SYSIN    DD  *                           
    SORT FIELDS=(01,05,CH,A)
/*                                         
//*                                        



Output :
21100       randip
21200       mandip     
21400       sandip

Note : Both input and output files are FB, if input and output files are VB then 4 bytes needs to added in starting position field.
ex : (05,05,CH,A)

2) SORT to copy the data as it is
//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A, 
//         NOTIFY=OZA201                   
//*                                        
//STEP010  EXEC PGM=SORT                   
//SYSOUT   DD  SYSOUT=*                    
//SYSPRINT DD  SYSOUT=*                    
//SORTIN   DD  DSN=OZA201.SORT.IN,DISP=SHR       
//SORTOUT  DD  DSN=OZA201.SORT.OUT,DISP=OLD
//SYSIN    DD  *                           
    SORT FIELDS=COPY
/*                                         
//*
     


Output : This sort will copy data from input file to output file as it is.


3) SORT to copy required number of  records

//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A, 
//         NOTIFY=OZA201                   
//*                                        
//STEP010  EXEC PGM=SORT                   
//SYSOUT   DD  SYSOUT=*                    
//SYSPRINT DD  SYSOUT=*                    
//SORTIN   DD  DSN=OZA201.SORT.IN,DISP=SHR       
//SORTOUT  DD  DSN=OZA201.SORT.OUT,DISP=OLD
//SYSIN       DD  *                           
    SORT FIELDS=COPY,               

    SKIPREC=02,STOPAFT=05  
/*                                         
//*     


SKIPREC will skip the records and STOPAFT will stop copyin records.

Input file data :
aaa rec1
bbb rec2
ccc rec4
ddd rec5
eee rec6
ggg rec7
hhh rec8
kkk rec9

Output file data :
ccc rec4
ddd rec5
eee rec6
ggg rec7
hhh rec8

4) SORT to format output data :

//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A, 
//         NOTIFY=OZA201                   
//*                                        
//STEP010  EXEC PGM=SORT                   
//SYSOUT   DD  SYSOUT=*                    
//SYSPRINT DD  SYSOUT=*                    
//SORTIN   DD  DSN=OZA201.SORT.IN,DISP=SHR    *(LRECL=80,RECFM=FB) 
//SORTOUT  DD  DSN=OZA201.SORT.OUT,DISP=OLD *(same as of input)
//SYSIN      DD  *                           
    SORT FIELDS=COPY               

    OUTREC FIELDS=(01:01,03,05:05,03,1X,10:C'OUTPUT RECS',61X)   
/*                                         
//*
   


Input file data :
AAA REC
BBB REC


Output file data :
AAA REC OUTPUT RECS                                                           
BBB REC OUTPUT RECS
                                                           



5) SORT to remove duplicate records :

//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A, 
//         NOTIFY=OZA201                   
//*                                        
//STEP010  EXEC PGM=SORT                   
//SYSOUT   DD  SYSOUT=*                    
//SYSPRINT DD  SYSOUT=*                    
//SORTIN   DD  DSN=OZA201.SORT.IN,DISP=SHR    *(LRECL=80,RECFM=FB) 
//SORTOUT  DD  DSN=OZA201.SORT.OUT,DISP=OLD *(same as of input)
//SYSIN    DD  *                           
    SORT FIELDS=(07,06,CH,A)
    SUM FIELDS=NONE
        

/*                                         
//* 
Input File data :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21400 SANDIP                                                           
21500 SANDIP                                                           
21200 RANDIP                                                           
21300 MANDIP                                                           
21700 KULDIP                                                           
21800 MANDIP                                                           
21900 MANDIP                                                           


Output file data :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21700 KULDIP                                                           
21800 MANDIP                                                           
21200 RANDIP                                                           
21400 SANDIP                                                           


 

6) SORT to copy duplicate records in seaperate file :

//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A, 
//         NOTIFY=OZA201                   
//*                                        
//STEP010  EXEC PGM=SORT                   
//SYSOUT   DD  SYSOUT=*                    
//SYSPRINT DD  SYSOUT=*                    
//SORTIN   DD  DSN=OZA201.SORT.IN,DISP=SHR    *(LRECL=80,RECFM=FB) 
//SORTOUT  DD  DSN=OZA201.SORT.OUT,DISP=OLD *(same as of input)

//SORTXSUM DD  DSN=OZA201.SORT.XSUM,DISP=OLD *(same as of input)
//SYSIN    DD  *                           
    SORT FIELDS=(07,06,CH,A)
    SUM FIELDS=NONE,XSUM
        

/*                                         
//*
 


Input File data :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21400 SANDIP                                                           
21500 SANDIP                                                           
21200 RANDIP                                                           
21300 MANDIP                                                           
21700 KULDIP                                                           
21800 MANDIP                                                           
21900 MANDIP                                                           


Output file data (SORTOUT) :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21700 KULDIP                                                           
21800 MANDIP                                                           
21200 RANDIP                                                           
21400 SANDIP      


Output file data (SORTXSUM) :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21900 MANDIP                                                           
21300 MANDIP                                                           
21500 SANDIP
                                                           

NOTE : SORTXSUM functionality doesn't work with DFSORT product, it only works with SYNCSORT. 

  
7) SORT to compare two input files for matching records :This sort will compare two input files on the basis emp-code field, if matches it will write records to output file.

//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A, 
//         NOTIFY=OZA201                   
//*                                        
//STEP010  EXEC PGM=SORT                   
//SYSOUT   DD  SYSOUT=*                    
//SYSPRINT DD  SYSOUT=*                    
//SORTJNF1 DD  DSN=OZA201.SORT.IN1,DISP=SHR  *(LRECL=80,RECFM=FB) 
//SORTJNF2 DD  DSN=OZA201.SORT.IN2,DISP=SHR  *(same as of input1)

//SORTOUT DD  DSN=OZA201.SORT.OUT,DISP=OLD *(same as of input1)
//SYSIN    DD  *        

      JOINKEYS FILE=F1,FIELDS=(01,05,A)
      JOINKEYS FILE=F2,FIELDS=(01,05,A)
      REFORMAT FIELDS=(F1:01,80)      
      SORT FIELDS=COPY
                
/*
//

Input1 file data :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21400 SANDIP KPO                                                       
21200 RANDIP BPO                                                       
21300 MANDIP BPO                                                       
21700 KULDIP KPO                     


Input2 file data :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21400                                                                  
21200                                                                  
21500                                                                  
21900                                                                   


Output file data :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21200 RANDIP BPO                                                       
21400 SANDIP KPO                                                       


To copy unmatching records in output file.

      JOINKEYS FILE=F1,FIELDS=(01,05,A)
      JOINKEYS FILE=F2,FIELDS=(01,05,A)

      JOIN UNPAIRED,F1,ONLY 
      REFORMAT FIELDS=(F1:01,80)      
      SORT FIELDS=COPY
   


Output file data :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21300 MANDIP BPO                                                       
21700 KULDIP KPO                                                       




1) Compare two files and write all matching records to output file. (INNER JOIN - ONLY MATCHING ROWS) 

//SORTJNF1
21400 SANDIP
21500 RANDIP
21600 KULDIP
21800 MANDIP
21900 BALDIP
//SORTJNF2
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN
//SYSIN DD *
    JOINKEYS FILE=F2,FIELDS=(1,5,A)
    JOINKEYS FILE=F1,FIELDS=(1,5,A)
    REFORMAT FIELDS=(F1:1,13,F2:1,12)      
    SORT FIELDS=COPY               
//*

OUTPUT:
21400 SANDIP 21400 PUNE
21500 RANDIP 21500 MUMBAI


=======================================================================
2) Compare two files and write matching as well as non-matching rows from File1 (LEFT OUTER JOIN - Matching and non-matching from F1) 

//SORTJNF1
21400 SANDIP
21500 RANDIP
21600 KULDIP
21800 MANDIP
21900 BALDIP
//SORTJNF2
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN
//SYSIN DD *
    JOINKEYS FILE=F1,FIELDS=(1,5,A)
    JOINKEYS FILE=F2,FIELDS=(1,5,A)
    JOIN UNPAIRED,F1
    REFORMAT FIELDS=(F1:01,13,F2:01,12)
    SORT FIELDS=COPY
//*

OUTPUT
21400 SANDIP 21400 PUNE
21500 RANDIP 21500 MUMBAI
21600 KULDIP
21800 MANDIP
21900 BALDIP 

=======================================================================
3) Compare two files and write NON-MATCHING rows from F1 ONLY. 
F2 we should not use in REFORMAT it will blank values 

//SORTJNF1
21400 SANDIP
21500 RANDIP
21600 KULDIP
21800 MANDIP
21900 BALDIP
//SORTJNF2
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN
//SYSIN DD *
    JOINKEYS FILE=F1,FIELDS=(1,5,A)
    JOINKEYS FILE=F2,FIELDS=(1,5,A)
    JOIN UNPAIRED,F1,ONLY 
    REFORMAT FIELDS=(F1:01,13) 
    SORT FIELDS=COPY
//*

OUTPUT: 
21600 KULDIP
21800 MANDIP
21900 BALDIP

=======================================================================
4) Compare two files and write matching as well as non-matching rows from File2 (RIGHT OUTER JOIN - Matching and non-matching from F2) 

//SORTJNF1
21400 SANDIP
21500 RANDIP
21600 KULDIP
21800 MANDIP
21900 BALDIP
//SORTJNF2
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN
//SYSIN DD *
    JOINKEYS FILE=F1,FIELDS=(1,5,A)
    JOINKEYS FILE=F2,FIELDS=(1,5,A)
    JOIN UNPAIRED,F2
    REFORMAT FIELDS=(F2:01,13) 
    SORT FIELDS=COPY
//*

OUTPUT: 
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN

=======================================================================
5) Compare two files and write ONLY non-matching rows from File2  

//SORTJNF1
21400 SANDIP
21500 RANDIP
21600 KULDIP
21800 MANDIP
21900 BALDIP
//SORTJNF2
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN
//SYSIN DD *
    JOINKEYS FILE=F1,FIELDS=(1,5,A)
    JOINKEYS FILE=F2,FIELDS=(1,5,A)
    JOIN UNPAIRED,F2,ONLY 
    REFORMAT FIELDS=(F2:01,13) 
    SORT FIELDS=COPY
//*

OUTPUT: 
22100 THANE
22200 KALYAN

=======================================================================
6) Compare two files and write matching as well non-matching rows (FULL OUTER JOIN)  

//SORTJNF1
21400 SANDIP
21500 RANDIP
21600 KULDIP
21800 MANDIP
21900 BALDIP
//SORTJNF2
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN
//MATCH       DD SYSOUT=*
//NOMATCH1 DD SYSOUT=*
//NOMATCH2 DD SYSOUT=*
//SYSIN DD *
    JOINKEYS FILE=F1,FIELDS=(1,5,A)
    JOINKEYS FILE=F2,FIELDS=(1,5,A)
    JOIN UNPAIRED,F1,F2
    REFORMAT FIELDS=(F1:01,13,
                                  F2:01,13,?)
    SORT FIELDS=COPY
*
    OUTFIL FNAMES=MATCH,
    INCLUDE=(27,01,CH,EQ,C'B'),
    BUILD=(01,27,)
*
    OUTFIL FNAMES=NOMATCH1,
    INCLUDE=(27,01,CH,EQ,C'1'),
    BUILD=(01,13,27,01)     
*
    OUTFIL FNAMES=NOMATCH2,
    INCLUDE=(27,01,CH,EQ,C'2'),
    BUILD=(14,13,27,01)
//*

OUTPUT: 
MATCH:
21400 SANDIP 21400 PUNE     B
21500 RANDIP 21500 MUMBAI B  

NOMATCH1:
21600 KULDIP 1
21800 MANDIP 1
21900 BALDIP 1

NOMATCH2:
22100 THANE  2
22200 KALYAN 2

*****Similar type to above **** 
Write matching and unmatching both records from both files in two output files -
//SORTJNF1 DD *
21400 SANDIP PUNE
21500 BALDIP MUMBAI 
21600 KULDIP HYDERABAD
21700 RANDIP THANE
//SORTJNF2 DD *
21400 TIETO
21700 SYNTEL
21800 TCS
21900 HSBC
//MATCH DD SYSOUT=*
//NOMTACH DD SYSOUT=*
//SYSIN DD * 
  JOINKEYS FILE=F1,FIELDS=(1,5,A)
  JOINKEYS FILE=F2,FIELDS=(1,5,A)
  REFORMAT FIELDS=(F1:01,25,F2:01,15,?)
  SORT FIELDS=COPY
  OUTFIL FNAMES=MATCH,INCLUDE=(41,01,CH,EQ,C'B'),
  BUILD=(01,40,40X)
  OUTFIL FNAMES=NOMATCH,INCLUDE=(41,01,CH,EQ,C'1',OR,
                                                         41,01,CH,EQ,C'2'),
  IFTHEN=(WHEN=(41,CH,EQ,C'1'),BUILD=(1,25)),
  IFTHEN=(WHEN=(41,CH,EQ,C'2'),BUILD=(26,15))
//*
MATCH OUTPUT
21400 SANDIP PUNE       21400 TIETO
21600 KULDIP THANE      21700 SYNTEL

NOMATCH OUTPUT
21500 BALDIP MUMBAI 
21600 KULDIP HYDERABAD
21800 TCS
21900 HSBC
      
=======================================================================
7) Compare two files and write ONLY non-matching rows from F1 & F2  

//SORTJNF1
21400 SANDIP
21500 RANDIP
21600 KULDIP
21800 MANDIP
21900 BALDIP
//SORTJNF2
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN
//SORTOUT       DD SYSOUT=*
//SYSIN DD *
    JOINKEYS FILE=F1,FIELDS=(1,5,A)
    JOINKEYS FILE=F2,FIELDS=(1,5,A)
    JOIN UNPAIRED,F1,F2,ONLY
    REFORMAT FIELDS=(F1:01,13,
                                  F2:01,13,?)
    SORT FIELDS=COPY

OUTPUT: 
MATCH:
21600 KULDIP                      1
21800 MANDIP                     1
21900 BALDIP                      1
                     22100 THANE  2
                     22200 KALYAN 2 

1 in the output file is printed because "?" was given in REFROMAT FIELDS.
==================================================


8) SORT to replace value of repetitive field :

//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A, 
//         NOTIFY=OZA201                   
//*                                        
//STEP010  EXEC PGM=SORT                   
//SYSOUT   DD  SYSOUT=*                    
//SYSPRINT DD  SYSOUT=*                    
//SORTIN    DD  DSN=OZA201.SORT.IN,DISP=SHR    *(LRECL=80,RECFM=FB) 
//SORTOUT  DD  DSN=OZA201.SORT.OUT,DISP=OLD *(same as of input)

//SYSIN      DD  *         
    SORT FIELDS=COPY                             
    OUTREC FINDREP=(IN=C'ABCD',OUT=C'ZZZZ')
      

/*

Input file data :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
SSSSSABCDSSSSSSSABCDSSSSSSSSSS                                         


Output file data :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
SSSSSZZZZSSSSSSSZZZZSSSSSSSSSS                                         


9) SORT to separate Odd and Even records from file :

This SORT will separate records on the basis of record number, if record number is odd, it will write record to ODD file, if record number is even then it will add record to EVEN file.

//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A, 
//         NOTIFY=OZA201                   
//*                                        
//STEP010  EXEC PGM=SORT                   
//SYSOUT   DD  SYSOUT=*                    
//SYSPRINT DD  SYSOUT=*                    
//SORTIN    DD  DSN=OZA201.SORT.IN,DISP=SHR   *(LRECL=80,RECFM=FB) 
//ODD        DD  DSN=OZA201.SORT.ODD,DISP=OLD *(same as of input)

//EVEN       DD  DSN=OZA201.SORT.EVEN,DISP=OLD *(same as of input)
//SYSIN      DD  *         
    SORT FIELDS=COPY             
    OUTFIL FNAMES=(ODD,EVEN),SPLIT

/*
//

Input file data :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
AAAAAAAAAAAAAAAAAAAAAAAAAA                                             
BBBBBBBBBBBBBBBBBBBBBBBBBB                                             
CCCCCCCCCCCCCCCCCCCCCCCCCC                                             
DDDDDDDDDDDDDDDDDDDDDDDDDD                                             
EEEEEEEEEEEEEEEEEEEEEEEEEE                                             
FFFFFFFFFFFFFFFFFFFFFFFFFF                                             


Output file data (ODD) :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
AAAAAAAAAAAAAAAAAAAAAAAAAA                                             
CCCCCCCCCCCCCCCCCCCCCCCCCC                                             
EEEEEEEEEEEEEEEEEEEEEEEEEE                                             


Output file data (EVEN) :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
BBBBBBBBBBBBBBBBBBBBBBBBBB                                             
DDDDDDDDDDDDDDDDDDDDDDDDDD                                             
FFFFFFFFFFFFFFFFFFFFFFFFFF                                             


10) SORT to do addition of numeric field :

This SORT will perform addition of numeric field.

//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A, 
//         NOTIFY=OZA201                   
//*                                        
//STEP010  EXEC PGM=SORT                   
//SYSOUT   DD  SYSOUT=*                    
//SYSPRINT DD  SYSOUT=*                    
//SORTIN    DD  DSN=OZA201.SORT.IN,DISP=SHR   *(LRECL=80,RECFM=FB) 
//SORTOUT DD  DSN=OZA201.SORT.OUT,DISP=OLD *(same as of input)

//SYSIN    DD  *         
   

    SORT FIELDS=(05,01,CH,A) 
    SUM FIELDS=(14,05,ZD)
    

/*
//


Input File data :
21300 SANDIP 10000                                                     
21400 MANDIP 15000                                                     
21500 RANDIP 15000                                                     
21600 KULDIP 20000                                                     
21700 BALDIP 25000                          


Output File data :                            
21300 SANDIP 85000



11) SORT to copy all duplicate records in one file and unique records in one file - For Syncsort v1.4 :


//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A,
//         NOTIFY=OZA201              
//*                                   
//STEP010  EXEC PGM=SORT              
//SYSOUT   DD  SYSOUT=*               
//SYSPRINT DD  SYSOUT=*               
//SORTIN    DD  *

01 SANDIP
02 MANDIP
03 RANDIP
04 BALDIP
//               DD  * 
02 MANDIP
04 MANJIT
//SORTOUT   DD  SYSOUT=*
//SORTXDUP DD  SYSOUT=*
//SYSIN    DD  *            
    SORT FIELDS=(01,09,CH,A)
    DUPKEYS ALLDUPS,XDUP

/*
//



11) SORT to add header & trailer in sort alongwith dates in different formats. ( used DFSORT)  


//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A,
//         NOTIFY=OZA201              
//*                                   
//STEP010  EXEC PGM=SORT              
//SYSOUT     DD  SYSOUT=*               
//SYSPRINT   DD  SYSOUT=*                

//SYSNAMES  DD  *                
MDT,S'&YR4.&LMON.&LDAY'
SDT,S'&LYR2.&LMON.&LDAY'
//SORTIN      DD  *
21400 SANDIP PUNE
21500 MANDIP PUNE
//SORTOUT   DD  SYSOUT=*
//SYSIN    DD  *            
       SORT FIELDS=COPY
   OUTFIL FILES=OUT,
   HEADER1=('00HEADER','YYYYMMDD:',MDT,'YYMMDD:',SDT),
   TRAILER1=('99TRAILER',COUNT=(M11,LENGTH=8)),REMOVECC
/*
//




SORTOUT data :   
00HEADERYYYYMMDD:20140219YYMMDD:140219
21400 SANDIP PUNE
21500 MANDIP PUNE
99TRAILER00000002

Instead of MDT & SDT If we give
DATENS=(4MD) ==> 20140219 (YYYYMMDD) 
DATENS=(DM4) ==> 19022014 (DDMMYYYY)
DATE=(4MD-)   ==> 2014-02-19 (YYYY-MM-DD)
DATE=(DM4-)   ==> 19-02-2014 (DD-MM-YYYY)
DATE=(4MD/)   ==> 2014/02/19 (YYYY/MM/DD)

DATE=(DM4/)   ==> 19/02/2014 (DD/MM/YYYY)

Format for time 

//SYSNAMES DD * 
TIM,S'&LHR.&LMIN.&LSEC'


NOTE : We can use SYSNAMES not only for header record but also for detail record also. 

Type SYM command in spool area and press ENTER it will show system names available.

                         

ICETOOL :
ICETOOL to find out number of records present in the file.

//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A, 
//         NOTIFY=OZA201                   
//*                                        
//SANDIP   EXEC PGM=ICETOOL                   
//TOOLMSG  DD  SYSOUT=*                         
//DFSMSG   DD  SYSOUT=*                         
//IN            DD  DSN=OZA201.TEST.IN,DISP=SHR 
//TOOLIN    DD  *                                
     COUNT FROM(IN)         
   

/*

OutPput:
    COUNT FROM(IN)                            SYNCSORT CALLED WITH IDENTIFIER "0001"          
NUMBER OF RECORDS PROCESSED: 000000000000008    
OPERATION COMPLETED WITH RETURN CODE 0          
                                                
SYNCTOOL PROCESSING COMPLETED WITH RETURN CODE 0



                                  

6) HOW to reverse file in JCL SORT:

//STEP1 EXEC PGM=SORT
//SORTIN DD *
SANDIP 123 DDD AAAAAAAA
MANDIP 345 AAA BBBBBBBBBBBBBBBBBBBBB
RANDIP 456 HHH QQQQQQQQQQQQQ
KULDIP GGGGG AAAAAAAAAA
//SORTOUT DD SYSOUT=*
//SYSIN DD *
    INREC FIELDS=(01,80,SEQNUM,08,ZD)
    SORT FIELDS=(81,08,ZD,D)
    OUTREC FIELDS=(01,80)
//*

OUTPUT:
KULDIP GGGGG AAAAAAAAAA
RANDIP 456 HHH QQQQQQQQQQQQQ 
MANDIP 345 AAA BBBBBBBBBBBBBBBBBBBBB
SANDIP 123 DDD AAAAAAAA


Procedures :

when same code is used repetitively, then that code is coded seperately either in instream of JCL or as a member of PDS, which can be called in JCL. 
There are two tyes of procedures 
1) Cataloged procedures : 
Procedures which are saved as member of PDS. It doesn't have PEND statement at end.

CATPROC procedure saved in XX7384A.CATPROC.LIB

//CATPROC PROC
//STEP1      EXEC PGM=IEFBR14
//SYSPRINT DD SYSOUT=*
//SYSOUT    DD SYSOUT=*
//DD1          DD DSN=XX7384A.NEW.PS,
//                DISP=(NEW,CATLG,DELETE),
//                UNIT=SYSDA,
//                DCB=(LRECL=80,RECFM=FB,BLKSIZE=800),
//                SPACE=(CYL,(2,3))
//*


JCL to execute CATPROC procedure - 
//OZA201AS JOB (GENERAL),'CATPROC CALL',CLASS=A,NOTIFY=OZA201
//*
// JCLLIB ORDER=XX7384A.CATPROC.LIB
//STEP1  EXEC CATPROC
//* 
in this JCL CATPROC cataloged proceure is executed. 


2) Instream procedures : 
Procedure written instream of JCL is known as Instream procedure. Instream procedures are defined before exec statement. It starts with PROC statement and ends with PEND statment. Maximum 15 Instream procedures can be coded in on JOB.


//OZA201AS JOB (GENERAL),'INPROC CALL',CLASS=A,NOTIFY=OZA201
//*
//INPROC PROC
//STEP1       EXEC PGM=IEFBR14
//SYSPRINT DD SYSOUT=*
//SYSOUT   DD SYSOUT=*
//DD1         DD DSN=XX7384A.NEW.PS,
//               DISP=(NEW,CATLG,DELETE),
//               UNIT=SYSDA,
//               DCB=(LRECL=80,RECFM=FB,BLKSIZE=800),
//               SPACE=(CYL,(2,3))
//             PEND
//*
//STEPX EXEC INPROC
//*

Here stepx is executing INPROC procedure. 

--

GDG : Generation data groups 

In production there are daily, weekly, quarterly, monthly or yearly running jobs, so in order to take BKUP of data, generally we use GDGs, there is no need to provide different names to datasets when you create, system on it's own will take care of it. 

These datasets are chronologically and functionally similar datasets.

Note : Under one GDG base datasets can be created with different combination of record length, record formats.


to create GDG datasets first we need to create GDG base, then GDG dataset can be created.
Maximum 255 datasets can be defined under one GDG base.

1) Create GDG base 

//OZA201AS JOB (GENERAL),'CRE GDG BASE',CLASS=A,   
//         NOTIFY=OZA201                     

//*     
//STEP1 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//SYSOUT    DD SYSOUT=*
//SYSIN       DD *
DEFINE GDG -
(NAME(XA7384A.GDG.BASE) - 
LIMIT(10) -
NOEMPTY -
SCRATCH -
)
//*

This JCL will create GDG base.


Parameters : 

1) LIMIT - 
It specifies maximum number of datasets that can be created under one GDG base.

2) NOEMPTY - It specifies older version.

3) EMPTY      - It specifies all versions. 
Either EMPTY or NOEMPTY can be used at one time. 

4) SCRATCH - It will delete dataset. 

5) NOSCRATCH - It will uncatalog dataset.  
Either SCRATCH or NOSCRATCH can be used at one time. 

Different combinations - 

LIMIT(10)
NOEMPTY 
SCRATCH
This combination will allow to create maximum 10 datasets when 11th dataset will be created it will delete 1st dataset(Older version). 


LIMIT(10)

NOEMPTY 
NOSCRATCH
This combination will allow to create maximum 10 datasets when 11th dataset will be created it will Uncatalog 1st dataset(Older version). 

LIMIT(10)
EMPTY 
SCRATCH
This combination will allow to create maximum 10 datasets when 11th dataset will be created it will Delete all previous 10 versions. 

LIMIT(10)
EMPTY 
NOSCRATCH
This combination will allow to create maximum 10 datasets when 11th dataset will be created it will Uncatalog all previous 10 versions. 



JCL to create GDG dataset :

//OZA201AS JOB (GENERAL),'CRE GDG DS',CLASS=A,   
//         NOTIFY=OZA201                     
//*     
//STEP1 EXEC PGM=IEFBR14
//SYSPRINT DD SYSOUT=*
//SYSOUT    DD SYSOUT=*
//DD1          DD DSN=XX7384A.GDG.BASE(+1),
//                DISP=(NEW,CATLG,DELETE),
//                UNIT=SYSDA,
//                DCB=(LRECL=80,RECFM=FB,BLKSIZE=800),
//                SPACE=(CYL,(2,3))
//* 

here +1 indicates new version,

0 indicates current version
-1 indicates previous version
-2 older then -1 and so on.... 

XA7384A.GDG.BASE              
XA7384A.GDG.BASE.G0001V00     
XA7384A.GDG.BASE.G0002V00
XA7384A.GDG.BASE.G0003V00



Note : GDG dataset will be updated after completion of JCL only. 

Abends :

When JCL/JOB terminates abnormally/unsuccessfully, it is called as job abend. It will give some specific abend code for specific reasons.


for example :

1) S322 - Time abend, when sufficient time is not provided to job.
2) SOC7 - Bad data
3) SO13 - Member not found
4) S806 - load module not found
5) S722 - When there is no space to write ouput in sysout.
6) S222 - Cancelled by operator.


Job to take unload of table - 

//YSWATEST JOB (GENERAL),'DB2 UNLOAD',                      
//         CLASS=A,                                         
//         MSGCLASS=Q,                                      
//         NOTIFY=&SYSUID,                                  
//         MSGLEVEL=(1,1),                                  
//         TIME=(0,1),                                      
//         PRTY=8                                           
//*                                                         
//STEP1    EXEC  PGM=IKJEFT01                               
//SYSTSPRT DD    SYSOUT=*                                   
//SYSPRINT DD    SYSOUT=*                                   
//SYSOUT    DD    SYSOUT=*                                   
//SYSIN      DD    *                                          
    SELECT *                                                
     FROM EMP_TABLE                                         
     WHERE EMP_NAME  = 'SANDIP'                                 
    WITH UR;                                                
//*                                                         
//SYSTSIN  DD    *                                          
   DSN SYSTEM(DBG2)                                         
   RUN PROGRAM(DSNTIAUL) PLAN(DSNTIAUL) PARMS('SQL')        
//*  DATA FILE                                              
//SYSREC00 DD    DSN=YSWA.DEV.DATA1X,                       
//             DISP=(NEW,CATLG,DELETE),                     
//             UNIT=SYSDA,SPACE=(CYL,(1,1))                 
//*  CTRL FILE                                              
//SYSPUNCH DD    DSN=YSWA.DEV.CTRL1X,                       
//             DISP=(NEW,CATLG,DELETE),                     
//             UNIT=SYSDA,SPACE=(CYL,(1,1))                 
//*                                                         


Execute JCL from JCL:

//NA7384AS JOB (UNIT TEST),'EXEC JCL',
//         CLASS=C,MSGCLASS=O,NOTIFY=&SYSUID
//*
//* THIS JCL WILL EXECUTE ANOTHER JCL FROM THIS JCL,
//* THIS IS JCL WITHIN JCL.
//*
//EXECJCL   EXEC PGM=IEBGENER
//SYSPRINT  DD SYSOUT=*
//SYSOUT    DD SYSOUT=*
//SYSUT2    DD SYSOUT=(A,INTRDR)
//SYSIN     DD DUMMY
//*
//SYSUT1    DD DATA,DLM=$$
//NA7384AS JOB (UNIT TEST),'INSIDE JCL',
//         CLASS=C,MSGCLASS=O,NOTIFY=&SYSUID,REGION=4096K
//*
//**********************************************************************
//* THIS IS INSIDE JCL, THIS JCL WILL BE EXECUTD FROM ABOVE JCL
//**********************************************************************
//*
//SORTSTEP  EXEC PGM=SORT
//SYSPRINT  DD SYSOUT=*
//SYSOUT    DD SYSOUT=*
//SORTIN    DD DSN=NA7384A.TEST.IN1,DISP=SHR
//SORTOUT   DD DSN=NA7384A.TEST.OUT1,DISP=OLD
//SYSIN     DD *
     SORT FIELDS=COPY
/*
//*
$$
//*

Find Commands in Dataset:

C ALL P'========' '        '  73 
This command will change all unknown characters from 73rd position to spaces.

F P'=' This command will find unknown characters.